replace MacAddress by Address

This commit is contained in:
Mathieu Lacage committed 2007-07-26 17:36:53 +02:00
1 parent ccc9c69b89
commit dbae783c9b
21 files changed
+83 -407

No files matched your search

+14
View File
@@ -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)
{
+1
View File
@@ -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];
-210
View File
@@ -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 <mathieu.lacage@sophia.inria.fr>
*/
#include <iostream>
#include <iomanip>
#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
-128
View File
@@ -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 <mathieu.lacage@sophia.inria.fr>
*/
#ifndef MAC_ADDRESS_H
#define MAC_ADDRESS_H
#include <stdint.h>
#include <ostream>
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 */
+5 -5
View File
@@ -32,7 +32,7 @@ namespace ns3 {
const InterfaceId NetDevice::iid = MakeInterfaceId ("NetDevice", Object::iid);
NetDevice::NetDevice(Ptr<Node> node, const MacAddress& addr) :
NetDevice::NetDevice(Ptr<Node> node, const Address& addr) :
m_node (node),
m_name(""),
m_ifIndex (0),
@@ -50,7 +50,7 @@ NetDevice::NetDevice(Ptr<Node> 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)
{
+11 -11
View File
@@ -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<Channel> 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> node, const MacAddress& addr);
NetDevice(Ptr<Node> 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<Node> 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;
-2
View File
@@ -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',