src/devices/bridge/bridge-net-device.h
author vincent@clarinet.u-strasbg.fr
Fri Nov 07 11:36:15 2008 -0800 (2008-11-07)
changeset 3852 9cf7ad0cac85
parent 3841 1e7abf5fca79
child 3936 e525995ce5dc
permissions -rw-r--r--
Initial IPv6 capability
gjc@3439
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
gjc@3439
     2
/*
gjc@3439
     3
 * This program is free software; you can redistribute it and/or modify
gjc@3439
     4
 * it under the terms of the GNU General Public License version 2 as
gjc@3439
     5
 * published by the Free Software Foundation;
gjc@3439
     6
 *
gjc@3439
     7
 * This program is distributed in the hope that it will be useful,
gjc@3439
     8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
gjc@3439
     9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
gjc@3439
    10
 * GNU General Public License for more details.
gjc@3439
    11
 *
gjc@3439
    12
 * You should have received a copy of the GNU General Public License
gjc@3439
    13
 * along with this program; if not, write to the Free Software
gjc@3439
    14
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
gjc@3439
    15
 *
gjc@3439
    16
 * Author: Gustavo Carneiro  <gjc@inescporto.pt>
gjc@3439
    17
 */
gjc@3439
    18
#ifndef BRIDGE_NET_DEVICE_H
gjc@3439
    19
#define BRIDGE_NET_DEVICE_H
gjc@3439
    20
gjc@3439
    21
#include "ns3/net-device.h"
gjc@3439
    22
#include "ns3/mac48-address.h"
gjc@3444
    23
#include "ns3/nstime.h"
gjc@3449
    24
#include "ns3/bridge-channel.h"
gjc@3439
    25
#include <stdint.h>
gjc@3439
    26
#include <string>
gjc@3444
    27
#include <map>
gjc@3439
    28
gjc@3439
    29
namespace ns3 {
gjc@3439
    30
gjc@3439
    31
class Node;
gjc@3439
    32
gjc@3439
    33
/**
gjc@3554
    34
 * \ingroup devices
gjc@3554
    35
 * \defgroup bridge Bridge
gjc@3439
    36
 * 
gjc@3554
    37
 * \brief a virtual net device that bridges multiple LAN segments
gjc@3554
    38
 *
gjc@3554
    39
 * The BridgeNetDevice object is a "virtual" netdevice that aggregates
gjc@3554
    40
 * multiple "real" netdevices and implements the data plane forwarding
gjc@3554
    41
 * part of IEEE 802.1D.  By adding a BridgeNetDevice to a Node, it
gjc@3554
    42
 * will act as a "bridge", or "switch", to multiple LAN segments.
gjc@3554
    43
 * 
gjc@3554
    44
 * By default the bridge netdevice implements a "learning bridge"
gjc@3554
    45
 * algorithm (see 802.1D), where incoming unicast frames from one port
gjc@3554
    46
 * may occasionally be forwarded throughout all other ports, but
gjc@3554
    47
 * usually they are forwarded only to a single correct output port.
gjc@3554
    48
 *
gjc@3554
    49
 * \attention The Spanning Tree Protocol part of 802.1D is not
gjc@3554
    50
 * implemented.  Therefore, you have to be careful not to create
gjc@3554
    51
 * bridging loops, or else the network will collapse.
gjc@3554
    52
 *
gjc@3554
    53
 * \attention Bridging is designed to work only with NetDevices
gjc@3554
    54
 * modelling IEEE 802-style technologies, such as CsmaNetDevice and
gjc@3554
    55
 * WifiNetDevice.
gjc@3554
    56
 *
gjc@3554
    57
 * \attention If including a WifiNetDevice in a bridge, the wifi
gjc@3554
    58
 * device must be in Access Point mode.  Adhoc mode is not supported
gjc@3554
    59
 * with bridging.
gjc@3554
    60
 */
gjc@3554
    61
gjc@3554
    62
/**
gjc@3554
    63
 * \ingroup bridge
gjc@3554
    64
 * \brief a virtual net device that bridges multiple LAN segments
gjc@3439
    65
 */
gjc@3439
    66
class BridgeNetDevice : public NetDevice
gjc@3439
    67
{
gjc@3439
    68
public:
gjc@3439
    69
  static TypeId GetTypeId (void);
gjc@3439
    70
  BridgeNetDevice ();
gjc@3439
    71
gjc@3554
    72
  /** \brief Add a 'port' to a bridge device
gjc@3554
    73
   *
gjc@3554
    74
   * This method adds a new bridge port to a BridgeNetDevice, so that
gjc@3554
    75
   * the new bridge port NetDevice becomes part of the bridge and L2
gjc@3554
    76
   * frames start being forwarded to/from this NetDevice.
gjc@3554
    77
   *
gjc@3554
    78
   * \attention The netdevice that is being added as bridge port must
gjc@3554
    79
   * _not_ have an IP address.  In order to add IP connectivity to a
gjc@3554
    80
   * bridging node you must enable IP on the BridgeNetDevice itself,
gjc@3554
    81
   * never on its port netdevices.
gjc@3554
    82
   */
gjc@3439
    83
  void AddBridgePort (Ptr<NetDevice> bridgePort);
gjc@3439
    84
gjc@3439
    85
  // inherited from NetDevice base class.
gjc@3439
    86
  virtual void SetName(const std::string name);
gjc@3439
    87
  virtual std::string GetName(void) const;
gjc@3439
    88
  virtual void SetIfIndex(const uint32_t index);
gjc@3439
    89
  virtual uint32_t GetIfIndex(void) const;
gjc@3439
    90
  virtual Ptr<Channel> GetChannel (void) const;
gjc@3439
    91
  virtual Address GetAddress (void) const;
gjc@3439
    92
  virtual bool SetMtu (const uint16_t mtu);
gjc@3439
    93
  virtual uint16_t GetMtu (void) const;
gjc@3439
    94
  virtual bool IsLinkUp (void) const;
gjc@3439
    95
  virtual void SetLinkChangeCallback (Callback<void> callback);
gjc@3439
    96
  virtual bool IsBroadcast (void) const;
gjc@3439
    97
  virtual Address GetBroadcast (void) const;
gjc@3439
    98
  virtual bool IsMulticast (void) const;
craigdo@3841
    99
  virtual Address GetMulticast (Ipv4Address multicastGroup) const;
gjc@3439
   100
  virtual bool IsPointToPoint (void) const;
gjc@3443
   101
  virtual bool Send (Ptr<Packet> packet, const Address& dest, uint16_t protocolNumber);
gjc@3443
   102
  virtual bool SendFrom (Ptr<Packet> packet, const Address& source, const Address& dest, uint16_t protocolNumber);
gjc@3439
   103
  virtual Ptr<Node> GetNode (void) const;
gjc@3439
   104
  virtual void SetNode (Ptr<Node> node);
gjc@3439
   105
  virtual bool NeedsArp (void) const;
gjc@3439
   106
  virtual void SetReceiveCallback (NetDevice::ReceiveCallback cb);
gjc@3460
   107
  virtual void SetPromiscReceiveCallback (NetDevice::PromiscReceiveCallback cb);
mathieu@3584
   108
  virtual bool SupportsSendFrom () const;
vincent@3852
   109
  virtual Address GetMulticast (Ipv6Address addr) const;
gjc@3439
   110
gjc@3439
   111
protected:
gjc@3439
   112
  virtual void DoDispose (void);
gjc@3439
   113
mathieu@3548
   114
  void ReceiveFromDevice (Ptr<NetDevice> device, Ptr<const Packet> packet, uint16_t protocol,
gjc@3448
   115
                          Address const &source, Address const &destination, PacketType packetType);
mathieu@3548
   116
  void ForwardUnicast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
gjc@3444
   117
                       uint16_t protocol, Mac48Address src, Mac48Address dst);
mathieu@3548
   118
  void ForwardBroadcast (Ptr<NetDevice> incomingPort, Ptr<const Packet> packet,
gjc@3444
   119
                         uint16_t protocol, Mac48Address src, Mac48Address dst);
gjc@3444
   120
  void Learn (Mac48Address source, Ptr<NetDevice> port);
gjc@3444
   121
  Ptr<NetDevice> GetLearnedState (Mac48Address source);
gjc@3439
   122
gjc@3439
   123
private:
gjc@3439
   124
  NetDevice::ReceiveCallback m_rxCallback;
gjc@3460
   125
  NetDevice::PromiscReceiveCallback m_promiscRxCallback;
gjc@3444
   126
gjc@3444
   127
  Mac48Address m_address;
gjc@3444
   128
  Time m_expirationTime; // time it takes for learned MAC state to expire
gjc@3444
   129
  struct LearnedState
gjc@3444
   130
  {
gjc@3444
   131
    Ptr<NetDevice> associatedPort;
gjc@3444
   132
    Time expirationTime;
gjc@3444
   133
  };
gjc@3444
   134
  std::map<Mac48Address, LearnedState> m_learnState;
gjc@3439
   135
  Ptr<Node> m_node;
gjc@3449
   136
  Ptr<BridgeChannel> m_channel;
gjc@3444
   137
  std::string m_name;
gjc@3444
   138
  std::vector< Ptr<NetDevice> > m_ports;
gjc@3444
   139
  uint32_t m_ifIndex;
gjc@3439
   140
  uint16_t m_mtu;
gjc@3444
   141
  bool m_enableLearning;
gjc@3439
   142
};
gjc@3439
   143
gjc@3439
   144
} // namespace ns3
gjc@3439
   145
gjc@3439
   146
#endif /* BRIDGE_NET_DEVICE_H */