From db6a90d956737d0dc4096d271084a0ffdf0c5876 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Thu, 26 Jul 2007 17:36:53 +0200 Subject: [PATCH] replace MacAddress by Address --- examples/simple-p2p.cc | 1 - src/devices/p2p/p2p-net-device.cc | 11 +- src/devices/p2p/p2p-net-device.h | 6 +- src/internet-node/arp-cache.cc | 4 +- src/internet-node/arp-cache.h | 8 +- src/internet-node/arp-header.cc | 12 +- src/internet-node/arp-header.h | 18 +- src/internet-node/arp-ipv4-interface.cc | 3 +- src/internet-node/arp-l3-protocol.cc | 10 +- src/internet-node/arp-l3-protocol.h | 6 +- src/internet-node/arp-private.cc | 2 +- src/internet-node/arp-private.h | 4 +- src/internet-node/header-utils.cc | 12 +- src/internet-node/header-utils.h | 6 +- src/node/eui48-address.cc | 14 ++ src/node/eui48-address.h | 1 + src/node/mac-address.cc | 210 ------------------------ src/node/mac-address.h | 128 --------------- src/node/net-device.cc | 10 +- src/node/net-device.h | 22 +-- src/node/wscript | 2 - 21 files changed, 83 insertions(+), 407 deletions(-) delete mode 100644 src/node/mac-address.cc delete mode 100644 src/node/mac-address.h diff --git a/examples/simple-p2p.cc b/examples/simple-p2p.cc index 9ad235b5e..ac98440c8 100644 --- a/examples/simple-p2p.cc +++ b/examples/simple-p2p.cc @@ -56,7 +56,6 @@ #include "ns3/internet-node.h" #include "ns3/p2p-channel.h" #include "ns3/p2p-net-device.h" -#include "ns3/mac-address.h" #include "ns3/ipv4-address.h" #include "ns3/ipv4.h" #include "ns3/socket.h" diff --git a/src/devices/p2p/p2p-net-device.cc b/src/devices/p2p/p2p-net-device.cc index 13d352889..3e0596d48 100644 --- a/src/devices/p2p/p2p-net-device.cc +++ b/src/devices/p2p/p2p-net-device.cc @@ -26,6 +26,7 @@ #include "ns3/queue.h" #include "ns3/simulator.h" #include "ns3/composite-trace-resolver.h" +#include "ns3/eui48-address.h" #include "p2p-net-device.h" #include "p2p-channel.h" @@ -38,10 +39,10 @@ DataRateDefaultValue PointToPointNetDevice::g_defaultRate( "The default data rate for point to point links", DataRate ("10Mb/s")); - PointToPointNetDevice::PointToPointNetDevice (Ptr node, - const DataRate& rate) +PointToPointNetDevice::PointToPointNetDevice (Ptr node, + const DataRate& rate) : - NetDevice(node, MacAddress (6)), + NetDevice(node, Eui48Address::Allocate ().ConvertTo ()), m_txMachineState (READY), m_bps (rate), m_tInterframeGap (Seconds(0)), @@ -54,7 +55,7 @@ DataRateDefaultValue PointToPointNetDevice::g_defaultRate( // BUGBUG FIXME // // You _must_ support broadcast to get any sort of packet from the ARP layer. - EnableBroadcast (MacAddress ("ff:ff:ff:ff:ff:ff")); + EnableBroadcast (Eui48Address ("ff:ff:ff:ff:ff:ff").ConvertTo ()); EnableMulticast(); EnablePointToPoint(); } @@ -82,7 +83,7 @@ void PointToPointNetDevice::SetInterframeGap(const Time& t) m_tInterframeGap = t; } -bool PointToPointNetDevice::SendTo (Packet& p, const MacAddress& dest) +bool PointToPointNetDevice::SendTo (Packet& p, const Address& dest) { NS_DEBUG ("PointToPointNetDevice::SendTo (" << &p << ", " << &dest << ")"); NS_DEBUG ("PointToPointNetDevice::SendTo (): UID is " << p.GetUid () << ")"); diff --git a/src/devices/p2p/p2p-net-device.h b/src/devices/p2p/p2p-net-device.h index a4bc3be00..474a6383c 100644 --- a/src/devices/p2p/p2p-net-device.h +++ b/src/devices/p2p/p2p-net-device.h @@ -22,7 +22,7 @@ #define POINT_TO_POINT_NET_DEVICE_H #include -#include "ns3/mac-address.h" +#include "ns3/address.h" #include "ns3/node.h" #include "ns3/net-device.h" #include "ns3/callback.h" @@ -201,10 +201,10 @@ private: * * @see NetDevice * @param p a reference to the packet to send - * @param dest a reference to the MacAddress of the destination device + * @param dest a reference to the Address of the destination device * @returns true if success, false on failure */ - virtual bool SendTo (Packet& p, const MacAddress& dest); + virtual bool SendTo (Packet& p, const Address& dest); /** * Start Sending a Packet Down the Wire. * diff --git a/src/internet-node/arp-cache.cc b/src/internet-node/arp-cache.cc index e9f48561d..4b166c99b 100644 --- a/src/internet-node/arp-cache.cc +++ b/src/internet-node/arp-cache.cc @@ -146,7 +146,7 @@ ArpCache::Entry::MarkDead (void) UpdateSeen (); } Packet -ArpCache::Entry::MarkAlive (MacAddress macAddress) +ArpCache::Entry::MarkAlive (Address macAddress) { NS_ASSERT (m_state == WAIT_REPLY); //NS_ASSERT (m_waiting != 0); @@ -180,7 +180,7 @@ ArpCache::Entry::MarkWaitReply (Packet waiting) UpdateSeen (); } -MacAddress +Address ArpCache::Entry::GetMacAddress (void) { NS_ASSERT (m_state == ALIVE); diff --git a/src/internet-node/arp-cache.h b/src/internet-node/arp-cache.h index 436d44eba..2cd88c85f 100644 --- a/src/internet-node/arp-cache.h +++ b/src/internet-node/arp-cache.h @@ -26,7 +26,7 @@ #include "ns3/nstime.h" #include "ns3/net-device.h" #include "ns3/ipv4-address.h" -#include "ns3/mac-address.h" +#include "ns3/address.h" #include "ns3/ptr.h" #include "sgi-hashmap.h" @@ -101,7 +101,7 @@ public: * \param macAddress * \return */ - Packet MarkAlive (MacAddress macAddress); + Packet MarkAlive (Address macAddress); /** * \param waiting */ @@ -127,7 +127,7 @@ public: /** * \return The MacAddress of this entry */ - MacAddress GetMacAddress (void); + Address GetMacAddress (void); /** * \return True if this entry has timedout; false otherwise. */ @@ -143,7 +143,7 @@ public: ArpCache *m_arp; ArpCacheEntryState_e m_state; Time m_lastSeen; - MacAddress m_macAddress; + Address m_macAddress; Packet m_waiting; }; diff --git a/src/internet-node/arp-header.cc b/src/internet-node/arp-header.cc index e340404f4..dc8cd3f7a 100644 --- a/src/internet-node/arp-header.cc +++ b/src/internet-node/arp-header.cc @@ -29,9 +29,9 @@ ArpHeader::~ArpHeader () {} void -ArpHeader::SetRequest (MacAddress sourceHardwareAddress, +ArpHeader::SetRequest (Address sourceHardwareAddress, Ipv4Address sourceProtocolAddress, - MacAddress destinationHardwareAddress, + Address destinationHardwareAddress, Ipv4Address destinationProtocolAddress) { m_type = ARP_TYPE_REQUEST; @@ -41,9 +41,9 @@ ArpHeader::SetRequest (MacAddress sourceHardwareAddress, m_ipv4Dest = destinationProtocolAddress; } void -ArpHeader::SetReply (MacAddress sourceHardwareAddress, +ArpHeader::SetReply (Address sourceHardwareAddress, Ipv4Address sourceProtocolAddress, - MacAddress destinationHardwareAddress, + Address destinationHardwareAddress, Ipv4Address destinationProtocolAddress) { m_type = ARP_TYPE_REPLY; @@ -62,12 +62,12 @@ ArpHeader::IsReply (void) const { return (m_type == ARP_TYPE_REPLY)?true:false; } -MacAddress +Address ArpHeader::GetSourceHardwareAddress (void) { return m_macSource; } -MacAddress +Address ArpHeader::GetDestinationHardwareAddress (void) { return m_macDest; diff --git a/src/internet-node/arp-header.h b/src/internet-node/arp-header.h index 9f85579f5..5affcf84f 100644 --- a/src/internet-node/arp-header.h +++ b/src/internet-node/arp-header.h @@ -23,7 +23,7 @@ #define ARP_HEADER_H #include "ns3/header.h" -#include "ns3/mac-address.h" +#include "ns3/address.h" #include "ns3/ipv4-address.h" namespace ns3 { @@ -34,18 +34,18 @@ class ArpHeader : public Header { public: virtual ~ArpHeader (); - void SetRequest (MacAddress sourceHardwareAddress, + void SetRequest (Address sourceHardwareAddress, Ipv4Address sourceProtocolAddress, - MacAddress destinationHardwareAddress, + Address destinationHardwareAddress, Ipv4Address destinationProtocolAddress); - void SetReply (MacAddress sourceHardwareAddress, + void SetReply (Address sourceHardwareAddress, Ipv4Address sourceProtocolAddress, - MacAddress destinationHardwareAddress, + Address destinationHardwareAddress, Ipv4Address destinationProtocolAddress); bool IsRequest (void) const; bool IsReply (void) const; - MacAddress GetSourceHardwareAddress (void); - MacAddress GetDestinationHardwareAddress (void); + Address GetSourceHardwareAddress (void); + Address GetDestinationHardwareAddress (void); Ipv4Address GetSourceIpv4Address (void); Ipv4Address GetDestinationIpv4Address (void); @@ -74,8 +74,8 @@ private: ARP_TYPE_REPLY = 2 }; uint16_t m_type; - MacAddress m_macSource; - MacAddress m_macDest; + Address m_macSource; + Address m_macDest; Ipv4Address m_ipv4Source; Ipv4Address m_ipv4Dest; }; diff --git a/src/internet-node/arp-ipv4-interface.cc b/src/internet-node/arp-ipv4-interface.cc index 42d6af238..9319929c2 100644 --- a/src/internet-node/arp-ipv4-interface.cc +++ b/src/internet-node/arp-ipv4-interface.cc @@ -24,6 +24,7 @@ #include "ns3/composite-trace-resolver.h" #include "ns3/node.h" #include "ns3/net-device.h" +#include "ns3/address.h" #include "arp-ipv4-interface.h" #include "arp-private.h" @@ -59,7 +60,7 @@ ArpIpv4Interface::SendTo (Packet p, Ipv4Address dest) if (GetDevice ()->NeedsArp ()) { Ptr arp = m_node->QueryInterface (ArpPrivate::iid); - MacAddress hardwareDestination; + Address hardwareDestination; bool found = arp->Lookup (p, dest, GetDevice (), &hardwareDestination); if (found) { diff --git a/src/internet-node/arp-l3-protocol.cc b/src/internet-node/arp-l3-protocol.cc index f04a6aa25..583b4e574 100644 --- a/src/internet-node/arp-l3-protocol.cc +++ b/src/internet-node/arp-l3-protocol.cc @@ -97,7 +97,7 @@ ArpL3Protocol::Receive(Packet& packet, Ptr device) } else if (arp.IsReply () && arp.GetDestinationIpv4Address ().IsEqual (cache->GetInterface ()->GetAddress ()) && - arp.GetDestinationHardwareAddress ().IsEqual (device->GetAddress ())) + arp.GetDestinationHardwareAddress () == device->GetAddress ()) { Ipv4Address from = arp.GetSourceIpv4Address (); ArpCache::Entry *entry = cache->Lookup (from); @@ -108,7 +108,7 @@ ArpL3Protocol::Receive(Packet& packet, Ptr device) NS_DEBUG ("node="<GetId ()<<", got reply from " << arp.GetSourceIpv4Address () << " for waiting entry -- flush"); - MacAddress from_mac = arp.GetSourceHardwareAddress (); + Address from_mac = arp.GetSourceHardwareAddress (); Packet waiting = entry->MarkAlive (from_mac); cache->GetInterface ()->Send (waiting, arp.GetSourceIpv4Address ()); } @@ -131,8 +131,8 @@ ArpL3Protocol::Receive(Packet& packet, Ptr device) } bool ArpL3Protocol::Lookup (Packet &packet, Ipv4Address destination, - Ptr device, - MacAddress *hardwareDestination) + Ptr device, + Address *hardwareDestination) { ArpCache *cache = FindCache (device); ArpCache::Entry *entry = cache->Lookup (destination); @@ -213,7 +213,7 @@ ArpL3Protocol::SendArpRequest (ArpCache const *cache, Ipv4Address to) } void -ArpL3Protocol::SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac) +ArpL3Protocol::SendArpReply (ArpCache const *cache, Ipv4Address toIp, Address toMac) { ArpHeader arp; arp.SetReply (cache->GetDevice ()->GetAddress (), diff --git a/src/internet-node/arp-l3-protocol.h b/src/internet-node/arp-l3-protocol.h index d27d2dba2..082bbebb5 100644 --- a/src/internet-node/arp-l3-protocol.h +++ b/src/internet-node/arp-l3-protocol.h @@ -23,7 +23,7 @@ #include #include "ns3/ipv4-address.h" -#include "ns3/mac-address.h" +#include "ns3/address.h" #include "ns3/ptr.h" #include "l3-protocol.h" @@ -64,14 +64,14 @@ public: */ bool Lookup (Packet &p, Ipv4Address destination, Ptr device, - MacAddress *hardwareDestination); + Address *hardwareDestination); protected: virtual void DoDispose (void); private: typedef std::list CacheList; ArpCache *FindCache (Ptr device); void SendArpRequest (ArpCache const *cache, Ipv4Address to); - void SendArpReply (ArpCache const *cache, Ipv4Address toIp, MacAddress toMac); + void SendArpReply (ArpCache const *cache, Ipv4Address toIp, Address toMac); CacheList m_cacheList; Ptr m_node; }; diff --git a/src/internet-node/arp-private.cc b/src/internet-node/arp-private.cc index 10a86b3e3..4f60dac99 100644 --- a/src/internet-node/arp-private.cc +++ b/src/internet-node/arp-private.cc @@ -40,7 +40,7 @@ ArpPrivate::~ArpPrivate () bool ArpPrivate::Lookup (Packet &p, Ipv4Address destination, Ptr device, - MacAddress *hardwareDestination) + Address *hardwareDestination) { return m_arp->Lookup (p, destination, device, hardwareDestination); } diff --git a/src/internet-node/arp-private.h b/src/internet-node/arp-private.h index 6e238ade0..af0b8b7a3 100644 --- a/src/internet-node/arp-private.h +++ b/src/internet-node/arp-private.h @@ -27,7 +27,7 @@ namespace ns3 { class NetDevice; -class MacAddress; +class Address; class Packet; class ArpL3Protocol; @@ -39,7 +39,7 @@ public: virtual ~ArpPrivate (); bool Lookup (Packet &p, Ipv4Address destination, Ptr device, - MacAddress *hardwareDestination); + Address *hardwareDestination); protected: virtual void DoDispose (void); private: diff --git a/src/internet-node/header-utils.cc b/src/internet-node/header-utils.cc index b3da88cfa..64bb29285 100644 --- a/src/internet-node/header-utils.cc +++ b/src/internet-node/header-utils.cc @@ -26,10 +26,10 @@ void WriteTo (Buffer::Iterator &i, Ipv4Address ad) { i.WriteHtonU32 (ad.GetHostOrder ()); } -void WriteTo (Buffer::Iterator &i, MacAddress ad) +void WriteTo (Buffer::Iterator &i, Address ad) { - uint8_t mac[MacAddress::MAX_LEN]; - ad.Peek (mac); + uint8_t mac[Address::MAX_SIZE]; + ad.CopyTo (mac); i.Write (mac, ad.GetLength ()); } @@ -37,11 +37,11 @@ void ReadFrom (Buffer::Iterator &i, Ipv4Address &ad) { ad.SetHostOrder (i.ReadNtohU32 ()); } -void ReadFrom (Buffer::Iterator &i, MacAddress &ad, uint32_t len) +void ReadFrom (Buffer::Iterator &i, Address &ad, uint32_t len) { - uint8_t mac[MacAddress::MAX_LEN]; + uint8_t mac[Address::MAX_SIZE]; i.Read (mac, len); - ad.Set (mac, len); + ad.CopyFrom (mac, len); } diff --git a/src/internet-node/header-utils.h b/src/internet-node/header-utils.h index e65e7533c..88d3dfe10 100644 --- a/src/internet-node/header-utils.h +++ b/src/internet-node/header-utils.h @@ -23,15 +23,15 @@ #include "ns3/buffer.h" #include "ns3/ipv4-address.h" -#include "ns3/mac-address.h" +#include "ns3/address.h" namespace ns3 { void WriteTo (Buffer::Iterator &i, Ipv4Address ad); -void WriteTo (Buffer::Iterator &i, MacAddress ad); +void WriteTo (Buffer::Iterator &i, Address ad); void ReadFrom (Buffer::Iterator &i, Ipv4Address &ad); -void ReadFrom (Buffer::Iterator &i, MacAddress &ad, uint32_t len); +void ReadFrom (Buffer::Iterator &i, Address &ad, uint32_t len); }; diff --git a/src/node/eui48-address.cc b/src/node/eui48-address.cc index 622ec3142..a3ed8fd4e 100644 --- a/src/node/eui48-address.cc +++ b/src/node/eui48-address.cc @@ -71,6 +71,20 @@ Eui48Address::ConvertFrom (const Address &address) address.CopyTo (retval.m_address); return retval; } +Eui48Address +Eui48Address::Allocate (void) +{ + static uint64_t id = 0; + id++; + Eui48Address address; + address.m_address[0] = (id >> 48) & 0xff; + address.m_address[1] = (id >> 32) & 0xff; + address.m_address[2] = (id >> 24) & 0xff; + address.m_address[3] = (id >> 16) & 0xff; + address.m_address[4] = (id >> 8) & 0xff; + address.m_address[5] = (id >> 0) & 0xff; + return address; +} uint8_t Eui48Address::GetType (void) { diff --git a/src/node/eui48-address.h b/src/node/eui48-address.h index 5f57971de..b051b4c31 100644 --- a/src/node/eui48-address.h +++ b/src/node/eui48-address.h @@ -14,6 +14,7 @@ public: Eui48Address (const char *str); Address ConvertTo (void) const; static Eui48Address ConvertFrom (const Address &address); + static Eui48Address Allocate (void); private: static uint8_t GetType (void); uint8_t m_address[6]; diff --git a/src/node/mac-address.cc b/src/node/mac-address.cc deleted file mode 100644 index 9dcf9bdd6..000000000 --- a/src/node/mac-address.cc +++ /dev/null @@ -1,210 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2005 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ - -#include -#include -#include "ns3/assert.h" -#include "mac-address.h" - -#define ASCII_a (0x41) -#define ASCII_z (0x5a) -#define ASCII_A (0x61) -#define ASCII_Z (0x7a) -#define ASCII_COLON (0x3a) -#define ASCII_ZERO (0x30) - -namespace ns3 { - -// Static variables -uint8_t MacAddress::g_nextAddress[MacAddress::MAX_LEN]; - -static char -AsciiToLowCase (char c) -{ - if (c >= ASCII_a && c <= ASCII_z) { - return c; - } else if (c >= ASCII_A && c <= ASCII_Z) { - return c + (ASCII_a - ASCII_A); - } else { - return c; - } -} - - -MacAddress::MacAddress () : m_len(0) -{ - for (int i=0; i < MacAddress::MAX_LEN; i++) - { - m_address[i] = 0; - } -} - -MacAddress::MacAddress(uint8_t len) : m_len(len) -{ - NS_ASSERT (len <= MacAddress::MAX_LEN); - AdvanceAddress(); - memcpy(m_address, g_nextAddress, len); -} - -MacAddress::MacAddress (uint8_t const *address, uint8_t len) -{ - NS_ASSERT (len <= MacAddress::MAX_LEN); - for (int i=0; i < len; i++) - { - m_address[i] = address[i]; - } - for (int i=len; i < MacAddress::MAX_LEN; i++) - { - m_address[i] = 0; - } - m_len = len; -} - -MacAddress::MacAddress (char const *str) -{ - int i = 0; - while (*str != 0 && i < MacAddress::MAX_LEN) { - uint8_t byte = 0; - while (*str != ASCII_COLON && *str != 0) { - byte <<= 4; - char low = AsciiToLowCase (*str); - if (low >= ASCII_a) { - byte |= low - ASCII_a + 10; - } else { - byte |= low - ASCII_ZERO; - } - str++; - } - m_address[i] = byte; - i++; - if (*str == 0) { - break; - } - str++; - } - m_len = i; -} - -MacAddress::~MacAddress () -{} - -bool -MacAddress::IsEqual (MacAddress other) const -{ - if (memcmp(other.m_address, m_address, m_len)) - { - return false; - } - else - { - return true; - } -} - -void -MacAddress::Print (std::ostream &os) const -{ - int i; - if (m_len == 0) - { - os << "NULL-ADDRESS"; - return; - } - os.setf (std::ios::hex, std::ios::basefield); - std::cout.fill('0'); - for (i=0; i< (m_len-1); i++) - { - os << std::setw(2) << (uint32_t)m_address[i] << ":"; - } - // Final byte not suffixed by ":" - os << std::setw(2) << (uint32_t)m_address[i]; - os.setf (std::ios::dec, std::ios::basefield); - std::cout.fill(' '); -} - -uint8_t -MacAddress::GetLength () const -{ - return m_len; -} - -void -MacAddress::Peek (uint8_t ad[MacAddress::MAX_LEN]) const -{ - memcpy (ad, m_address, MacAddress::MAX_LEN); -} -void -MacAddress::Set (uint8_t const ad[MacAddress::MAX_LEN], uint8_t len) -{ - memcpy (m_address, ad, MacAddress::MAX_LEN); - m_len = len; -} - -// Static methods -void MacAddress::AdvanceAddress() - { - // Advance to next address, little end first - for(size_t i = 0; i < MAX_LEN; ++i) - { - if (++g_nextAddress[i] != 0) break; - } - } - -// Non-member operators -bool operator == (MacAddress const&a, MacAddress const&b) -{ - return a.IsEqual (b); -} - -bool operator != (MacAddress const&a, MacAddress const&b) -{ - return !a.IsEqual (b); -} - -bool operator < (MacAddress const&a, MacAddress const&b) -{ - uint8_t a_p[MacAddress::MAX_LEN]; - uint8_t b_p[MacAddress::MAX_LEN]; - a.Peek (a_p); - b.Peek (b_p); - NS_ASSERT (a.GetLength() == b.GetLength()); - for (uint8_t i = 0; i < a.GetLength(); i++) - { - if (a_p[i] < b_p[i]) - { - return true; - } - else if (a_p[i] > b_p[i]) - { - return false; - } - } - return false; -} - -std::ostream& operator<< (std::ostream& os, MacAddress const& address) -{ - address.Print (os); - return os; -} - - -}; // namespace ns3 diff --git a/src/node/mac-address.h b/src/node/mac-address.h deleted file mode 100644 index 76c5a6ae0..000000000 --- a/src/node/mac-address.h +++ /dev/null @@ -1,128 +0,0 @@ -/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ -/* - * Copyright (c) 2005 INRIA - * All rights reserved. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation; - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Author: Mathieu Lacage - */ - -#ifndef MAC_ADDRESS_H -#define MAC_ADDRESS_H - -#include -#include - -namespace ns3 { - -/** - * \brief base class for Network Device addresses - * - * This class is a base class for different types of Network - * Device addresses. It generically stores an address of - * MAX_ADDR_LEN bytes, and provides methods to compare, print, and set - * the address. - */ -class MacAddress { -public: - enum { - MAX_LEN = 32 - }; - /** - * \brief Construct a null MacAddress - * - * This MacAddress has length of zero, and is internally all zeros - */ - MacAddress (void); - /** - * \brief Construct a MacAddress using the next available - * address. - * \see MacAddres::Next - * \param len length, in bytes, of the desired address - */ - MacAddress(uint8_t len); - /** - * \brief Construct a MacAddress from a byte-array - * - * low byte should be first. - * \param address a byte array indicating the address - * \param len length, in bytes, of the address points to - */ - MacAddress (uint8_t const *address, uint8_t len); - /** - * \brief Construct a MacAddress from a C-string - * - * The string should look like this: - * hh:xx:xx:xx:xx:ll - * where hh is the high byte and ll is - * the low byte. - * \param address the C-string representation of the address - */ - MacAddress (char const *address); - ~MacAddress (); - - /** - * \brief Comparison operation between MacAddresses - * \param other The address against which to compare this one - * \return True if they are equal, false otherwise. - */ - bool IsEqual (MacAddress other) const; - /** - * \brief Print this MacAddress to a stream - * - * The format is colon seperated groups of two hexadecimal digits - * \param os The output stream desired - */ - void Print (std::ostream &os) const; - - /** - * \return The length in bytes of this MacAddress - */ - uint8_t GetLength() const; - /** - * \brief Copy routine to peek the contents of the MacAddress - * - * \param ad Output parameter which holds a copy of this MacAddress - */ - void Peek (uint8_t ad[MAX_LEN]) const; - /** - * \brief Sets this MacAddress to a specific value - * \param ad byte buffer to set the MacAddress to - * \param len the length of the buffer - */ - void Set (uint8_t const ad[MAX_LEN], uint8_t len); - - // Static methods/members - /** - * - * Advance the global to the next available mac address. - */ - static void AdvanceAddress(); - static uint8_t g_nextAddress[MAX_LEN]; - -private: - uint8_t m_address[MAX_LEN]; - uint8_t m_len; -}; - -bool operator == (MacAddress const&a, MacAddress const&b); -bool operator != (MacAddress const&a, MacAddress const&b); -bool operator < (MacAddress const&a, MacAddress const&b); - -std::ostream& operator<< (std::ostream& os, MacAddress const& address); - -}; // namespace ns3 - -#endif /* MAC_ADDRESS_H */ diff --git a/src/node/net-device.cc b/src/node/net-device.cc index 5774abeac..1a9163aad 100644 --- a/src/node/net-device.cc +++ b/src/node/net-device.cc @@ -32,7 +32,7 @@ namespace ns3 { const InterfaceId NetDevice::iid = MakeInterfaceId ("NetDevice", Object::iid); -NetDevice::NetDevice(Ptr node, const MacAddress& addr) : +NetDevice::NetDevice(Ptr node, const Address& addr) : m_node (node), m_name(""), m_ifIndex (0), @@ -50,7 +50,7 @@ NetDevice::NetDevice(Ptr node, const MacAddress& addr) : NetDevice::~NetDevice () {} -MacAddress +Address NetDevice::GetAddress (void) const { return m_address; @@ -110,7 +110,7 @@ NetDevice::IsBroadcast (void) const { return m_isBroadcast; } -MacAddress const & +Address const & NetDevice::GetBroadcast (void) const { NS_ASSERT (m_isBroadcast); @@ -118,7 +118,7 @@ NetDevice::GetBroadcast (void) const } void -NetDevice::EnableBroadcast (MacAddress broadcast) +NetDevice::EnableBroadcast (Address broadcast) { m_isBroadcast = true; m_broadcast = broadcast; @@ -168,7 +168,7 @@ NetDevice::DisablePointToPoint (void) // Receive packet from above bool -NetDevice::Send(Packet& p, const MacAddress& dest, uint16_t protocolNumber) +NetDevice::Send(Packet& p, const Address& dest, uint16_t protocolNumber) { if (m_isUp) { diff --git a/src/node/net-device.h b/src/node/net-device.h index 522b1ed41..9dace11e5 100644 --- a/src/node/net-device.h +++ b/src/node/net-device.h @@ -27,7 +27,7 @@ #include "ns3/packet.h" #include "ns3/object.h" #include "ns3/ptr.h" -#include "mac-address.h" +#include "address.h" namespace ns3 { @@ -78,9 +78,9 @@ public: Ptr GetChannel (void) const; /** - * \return the current MacAddress of this interface. + * \return the current Address of this interface. */ - MacAddress GetAddress (void) const; + Address GetAddress (void) const; /** * \param mtu MTU value, in bytes, to set for the device * \return whether the MTU value was within legal bounds @@ -136,7 +136,7 @@ public: * Calling this method is invalid if IsBroadcast returns * not true. */ - MacAddress const &GetBroadcast (void) const; + Address const &GetBroadcast (void) const; /** * \return value of m_isMulticast flag */ @@ -153,11 +153,11 @@ public: * is received. * * Called from higher layer to send packet into Network Device - * to the specified destination MacAddress + * to the specified destination Address * * \return whether the Send operation succeeded */ - bool Send(Packet& p, const MacAddress& dest, uint16_t protocolNumber); + bool Send(Packet& p, const Address& dest, uint16_t protocolNumber); /** * \returns the node base class which contains this network * interface. @@ -187,12 +187,12 @@ public: * \param node base class node pointer of device's node * \param addr MAC address of this device. */ - NetDevice(Ptr node, const MacAddress& addr); + NetDevice(Ptr node, const Address& addr); /** * Enable broadcast support. This method should be * called by subclasses from their constructor */ - void EnableBroadcast (MacAddress broadcast); + void EnableBroadcast (Address broadcast); /** * Set m_isBroadcast flag to false */ @@ -255,7 +255,7 @@ public: * method. When the link is Up, this method is invoked to ask * subclasses to forward packets. Subclasses MUST override this method. */ - virtual bool SendTo (Packet& p, const MacAddress& dest) = 0; + virtual bool SendTo (Packet& p, const Address& dest) = 0; /** * \returns true if this NetDevice needs the higher-layers * to perform ARP over it, false otherwise. @@ -282,8 +282,8 @@ public: Ptr m_node; std::string m_name; uint16_t m_ifIndex; - MacAddress m_address; - MacAddress m_broadcast; + Address m_address; + Address m_broadcast; uint16_t m_mtu; bool m_isUp; bool m_isBroadcast; diff --git a/src/node/wscript b/src/node/wscript index e11cd8eac..738402fd3 100644 --- a/src/node/wscript +++ b/src/node/wscript @@ -12,7 +12,6 @@ def build(bld): 'node.cc', 'ipv4-address.cc', 'net-device.cc', - 'mac-address.cc', 'llc-snap-header.cc', 'ipv4-route.cc', 'queue.cc', @@ -35,7 +34,6 @@ def build(bld): 'node.h', 'ipv4-address.h', 'net-device.h', - 'mac-address.h', 'ipv4-route.h', 'queue.h', 'drop-tail-queue.h',