From: Richard Whitehouse Date: Mon, 24 Jan 2011 12:09:25 +0000 (+0000) Subject: Created MOOSE Bridge Net Device. Added MOOSE Addressing. X-Git-Url: https://git.richardwhiuk.com/?a=commitdiff_plain;h=60fbc46cf80c258ad4df54849276ef77099d7ca7;p=ns-moose.git Created MOOSE Bridge Net Device. Added MOOSE Addressing. Todo: Implement packet rewriting in Moose Net Device. --- diff --git a/code/src/devices/bridge/model/bridge-net-device.cc b/code/src/devices/bridge/model/bridge-net-device.cc index 853997f..602426d 100644 --- a/code/src/devices/bridge/model/bridge-net-device.cc +++ b/code/src/devices/bridge/model/bridge-net-device.cc @@ -13,6 +13,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + * Author: Richard Whitehouse * Author: Gustavo Carneiro */ #include "bridge-net-device.h" @@ -228,19 +229,26 @@ BridgeNetDevice::AddBridgePort (Ptr device) NS_LOG_FUNCTION_NOARGS (); NS_ASSERT (device != this); -// This is probably wrong and needs fixing. + + NS_LOG_DEBUG("AddBridgePort(bridge_addr=" << m_address << ", device_address=" << (Mac48Address::ConvertFrom(device->GetAddress()))); + if (m_address == Mac48Address ()) { m_address = Mac48Address::ConvertFrom (device->GetAddress ()); } - Ptr port = CreateObject(this, device, m_node); + Ptr port = CreateBridgePort(this, device, m_node); m_ports.push_back(port); m_channel->AddChannel (device->GetChannel ()); } +Ptr +BridgeNetDevice::CreateBridgePort(Ptr bridge, Ptr device, Ptr node){ + return CreateObject(bridge, device, node); +} + void BridgeNetDevice::SetIfIndex(const uint32_t index) { diff --git a/code/src/devices/bridge/model/bridge-net-device.h b/code/src/devices/bridge/model/bridge-net-device.h index 947e05c..a005f1a 100644 --- a/code/src/devices/bridge/model/bridge-net-device.h +++ b/code/src/devices/bridge/model/bridge-net-device.h @@ -24,6 +24,7 @@ #include "ns3/mac48-address.h" #include "ns3/nstime.h" #include "ns3/bridge-channel.h" +#include "ns3/object-factory.h" #include #include #include @@ -120,11 +121,13 @@ public: protected: virtual void DoDispose (void); - void Forward (Ptr port, Ptr packet, uint16_t protocol, Address const &src, Address const &dst, PacketType packetType); - void ForwardUnicast (Ptr incomingPort, Ptr packet, uint16_t protocol, Mac48Address src, Mac48Address dst); - void ForwardBroadcast (Ptr incomingPort, Ptr packet, uint16_t protocol, Mac48Address src, Mac48Address dst); - void Learn (Address const &src, Ptr port); - Ptr GetLearnedState (Mac48Address source); + virtual void Forward (Ptr port, Ptr packet, uint16_t protocol, Address const &src, Address const &dst, PacketType packetType); + virtual void ForwardUnicast (Ptr incomingPort, Ptr packet, uint16_t protocol, Mac48Address src, Mac48Address dst); + virtual void ForwardBroadcast (Ptr incomingPort, Ptr packet, uint16_t protocol, Mac48Address src, Mac48Address dst); + virtual void Learn (Address const &src, Ptr port); + virtual Ptr GetLearnedState (Mac48Address source); + + virtual Ptr CreateBridgePort(Ptr bridge, Ptr device, Ptr node); private: NetDevice::ReceiveCallback m_rxCallback; diff --git a/code/src/devices/bridge/model/bridge-port-net-device.h b/code/src/devices/bridge/model/bridge-port-net-device.h index b9d62bf..ccc3da0 100644 --- a/code/src/devices/bridge/model/bridge-port-net-device.h +++ b/code/src/devices/bridge/model/bridge-port-net-device.h @@ -13,7 +13,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Author: Gustavo Carneiro * Author: Richard Whitehouse */ #ifndef BRIDGE_PORT_NET_DEVICE_H diff --git a/code/src/devices/bridge/model/moose-bridge-net-device.cc b/code/src/devices/bridge/model/moose-bridge-net-device.cc new file mode 100644 index 0000000..f066c3b --- /dev/null +++ b/code/src/devices/bridge/model/moose-bridge-net-device.cc @@ -0,0 +1,70 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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: Richard Whitehouse + * Author: Gustavo Carneiro + */ + +#include "moose-bridge-net-device.h" +#include "moose-bridge-port-net-device.h" +#include "ns3/log.h" +#include "ns3/node.h" + +NS_LOG_COMPONENT_DEFINE ("MooseBridgeNetDevice"); + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED (MooseBridgeNetDevice); + +TypeId +MooseBridgeNetDevice::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::MooseBridgeNetDevice") + .SetParent () + .AddConstructor (); + return tid; +} + +MooseBridgeNetDevice::MooseBridgeNetDevice() : BridgeNetDevice() { + NS_LOG_FUNCTION_NOARGS (); + + m_mooseAddress = MooseAddress::Allocate(); + +} + +MooseBridgeNetDevice::~MooseBridgeNetDevice(){ + NS_LOG_FUNCTION_NOARGS (); +} + +Ptr MooseBridgeNetDevice::CreateBridgePort(Ptr bridge, Ptr device, Ptr node){ + return CreateObject(bridge, device, node); +} + +/* +//bool Send (Ptr packet, const Address& dest, uint16_t protocolNumber); +//bool SendFrom (Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber); + +void Forward (Ptr port, Ptr packet, uint16_t protocol, Address const &src, Address const &dst, PacketType packetType){ + +} + +void ForwardUnicast (Ptr incomingPort, Ptr packet, uint16_t protocol, Mac48Address src, Mac48Address dst); +void ForwardBroadcast (Ptr incomingPort, Ptr packet, uint16_t protocol, Mac48Address src, Mac48Address dst); +void Learn (Address const &src, Ptr port); +Ptr GetLearnedState (Mac48Address source);*/ + + +} + diff --git a/code/src/devices/bridge/model/moose-bridge-net-device.h b/code/src/devices/bridge/model/moose-bridge-net-device.h new file mode 100644 index 0000000..9f39dcb --- /dev/null +++ b/code/src/devices/bridge/model/moose-bridge-net-device.h @@ -0,0 +1,103 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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: Richard Whitehouse + */ +#ifndef MOOSE_BRIDGE_NET_DEVICE_H +#define MOOSE_BRIDGE_NET_DEVICE_H + +#include "bridge-net-device.h" +#include "ns3/moose-address.h" +#include "ns3/moose-prefix-address.h" +#include "ns3/moose-suffix-address.h" + +namespace ns3 { + +/** + * \ingroup bridge + * \brief a virtual net device that bridges multiple LAN segments + * + * MOOSE (Multi-Level Origin Organised Scalable Ethernet) Implementation + */ +class MooseBridgeNetDevice : public BridgeNetDevice +{ + +public: + static TypeId GetTypeId (void); + MooseBridgeNetDevice (); + virtual ~MooseBridgeNetDevice (); + +protected: + +// From NetDevice + +// Unconvinced we need these... + +// virtual bool Send (Ptr packet, const Address& dest, uint16_t protocolNumber); +// virtual bool SendFrom (Ptr packet, const Address& source, const Address& dest, uint16_t protocolNumber); + +// From BridgeNetDevice + +/* + + virtual void Forward (Ptr port, Ptr packet, uint16_t protocol, Address const &src, Address const &dst, PacketType packetType); + virtual void ForwardUnicast (Ptr incomingPort, Ptr packet, uint16_t protocol, Mac48Address src, Mac48Address dst); + virtual void ForwardBroadcast (Ptr incomingPort, Ptr packet, uint16_t protocol, Mac48Address src, Mac48Address dst); + virtual void Learn (Address const &src, Ptr port); + virtual Ptr GetLearnedState (Mac48Address source); */ + + virtual Ptr CreateBridgePort(Ptr bridge, Ptr device, Ptr node); + +private: + +// Need more types of state + +/** + Local Port Mappings + -- Implemented in parent. + + struct LearnedState + { + Ptr associatedPort; + Time expirationTime; + }; + std::map m_learnState; +**/ + + MooseAddress m_mooseAddress; + + // Remote Moose State + + struct PrefixState + { + Ptr associatedPort; + Time expirationTime; + }; + std::map m_remoteState; + + // Local Moose State + + struct SuffixState + { + Mac48Address ethernetAddr; + Time expirationTime; + }; + std::map m_localState; + +}; + +} // namespace ns3 + +#endif diff --git a/code/src/devices/bridge/model/moose-bridge-port-net-device.cc b/code/src/devices/bridge/model/moose-bridge-port-net-device.cc new file mode 100644 index 0000000..59a74ca --- /dev/null +++ b/code/src/devices/bridge/model/moose-bridge-port-net-device.cc @@ -0,0 +1,56 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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: Richard Whitehouse + */ + +#include "bridge-net-device.h" +#include "moose-bridge-net-device.h" +#include "bridge-port-net-device.h" +#include "moose-bridge-port-net-device.h" +#include "ns3/node.h" +#include "ns3/channel.h" +#include "ns3/packet.h" +#include "ns3/log.h" +#include "ns3/boolean.h" +#include "ns3/simulator.h" +#include "ns3/uinteger.h" + +NS_LOG_COMPONENT_DEFINE ("MooseBridgePortNetDevice"); + +namespace ns3 { + +NS_OBJECT_ENSURE_REGISTERED (MooseBridgePortNetDevice); + +TypeId +MooseBridgePortNetDevice::GetTypeId (void) +{ + static TypeId tid = TypeId ("ns3::MooseBridgePortNetDevice") + .SetParent () + ; + return tid; +} + +MooseBridgePortNetDevice::MooseBridgePortNetDevice(Ptr bridge, Ptr device, Ptr node) : BridgePortNetDevice(bridge,device,node){ + NS_LOG_FUNCTION_NOARGS (); +} + +MooseBridgePortNetDevice::~MooseBridgePortNetDevice(){ + NS_LOG_FUNCTION_NOARGS (); +} + +} + + diff --git a/code/src/devices/bridge/model/moose-bridge-port-net-device.h b/code/src/devices/bridge/model/moose-bridge-port-net-device.h new file mode 100644 index 0000000..f0dfa78 --- /dev/null +++ b/code/src/devices/bridge/model/moose-bridge-port-net-device.h @@ -0,0 +1,54 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/* + * 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: Richard Whitehouse + */ +#ifndef MOOSE_BRIDGE_PORT_NET_DEVICE_H +#define MOOSE_BRIDGE_PORT_NET_DEVICE_H + +#include "bridge-port-net-device.h" +#include "ns3/net-device.h" +#include "ns3/mac48-address.h" +#include "ns3/moose-address.h" +#include "ns3/moose-prefix-address.h" +#include "ns3/moose-suffix-address.h" +#include "ns3/nstime.h" +#include +#include +#include + +namespace ns3 { + +class Node; +class BridgeNetDevice; + +/** + * \ingroup bridge + * \brief a port on a virtual net device that bridges multiple LAN segments + */ + +class MooseBridgePortNetDevice : public BridgePortNetDevice { + +public: + MooseBridgePortNetDevice(Ptr bridge, Ptr device, Ptr node); + virtual ~MooseBridgePortNetDevice(); + + static TypeId GetTypeId (void); + +}; + +} + +#endif diff --git a/code/src/devices/bridge/wscript b/code/src/devices/bridge/wscript index a14d756..13d18be 100644 --- a/code/src/devices/bridge/wscript +++ b/code/src/devices/bridge/wscript @@ -3,6 +3,8 @@ def build(bld): obj = bld.create_ns3_module('bridge', ['node']) obj.source = [ + 'model/moose-bridge-port-net-device.cc', + 'model/moose-bridge-net-device.cc', 'model/bridge-net-device.cc', 'model/bridge-port-net-device.cc', 'model/bridge-channel.cc', @@ -11,6 +13,8 @@ def build(bld): headers = bld.new_task_gen('ns3header') headers.module = 'bridge' headers.source = [ + 'model/moose-bridge-port-net-device.h', + 'model/moose-bridge-net-device.h', 'model/bridge-net-device.h', 'model/bridge-port-net-device.h', 'model/bridge-channel.h', diff --git a/code/src/node/mac48-address.h b/code/src/node/mac48-address.h index 936cec0..f75e3a6 100644 --- a/code/src/node/mac48-address.h +++ b/code/src/node/mac48-address.h @@ -125,6 +125,7 @@ public: * \returns a multicast address. */ static Mac48Address GetMulticast6Prefix (void); + private: /** * \returns a new Address instance diff --git a/code/src/node/moose-address.cc b/code/src/node/moose-address.cc new file mode 100644 index 0000000..ab300a0 --- /dev/null +++ b/code/src/node/moose-address.cc @@ -0,0 +1,102 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * + * 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: Richard Whitehouse + */ + +#include "moose-address.h" +#include + +namespace ns3 { + +MooseAddress::MooseAddress (){ + memset (m_address, 0, 6); +} + +MooseAddress::MooseAddress (const char *str) { + memset (m_address, 0, 6); + Mac48Address mac(str); + mac.CopyTo(m_address); +} + +MooseAddress::MooseAddress (const Mac48Address &mac) { + memset (m_address, 0, 6); + mac.CopyTo(m_address); +} + +const MoosePrefixAddress MooseAddress::GetMoosePrefix() const +{ + MoosePrefixAddress prefix(m_address + 1); + return prefix; +} + +const MooseSuffixAddress MooseAddress::GetMooseSuffix() const +{ + MooseSuffixAddress suffix(m_address + 3); + return suffix; +} + +const Mac48Address MooseAddress::GetMacAddress() const +{ + Mac48Address mac; + mac.CopyFrom(m_address); + return mac; +} + +bool MooseAddress::IsMoose () const +{ + return (m_address[0] & 0x02) == 0x02; +} + +MooseAddress MooseAddress::Allocate() +{ + static uint16_t id = 0; + ++id; + + MooseAddress moose; + + moose.m_address[0] = 0 | 0x02; + moose.m_address[1] = (id >> 8) & 0xff; + moose.m_address[2] = (id >> 0) & 0xff; + + return moose; +} + +MooseAddress MooseAddress::Allocate(MoosePrefixAddress prefix){ + + static std::map ids; + + uint16_t key = prefix.GetInt(); + + uint16_t val = ++ids[key]; + + MooseAddress moose; + moose.m_address[0] = 0 | 0x02; // MOOSE Address + + moose.m_address[1] = (key >> 8) & 0xff; // Bridge + moose.m_address[2] = (key >> 0) & 0xff; + + moose.m_address[3] = (val >> 16) & 0xff; // Port + moose.m_address[4] = (val >> 8) & 0xff; + moose.m_address[5] = (val >> 0) & 0xff; + + return moose; + +} + +} + diff --git a/code/src/node/moose-address.h b/code/src/node/moose-address.h new file mode 100644 index 0000000..74253de --- /dev/null +++ b/code/src/node/moose-address.h @@ -0,0 +1,88 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * + * 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: Richard Whitehouse + */ +#ifndef MOOSE_ADDRESS_H +#define MOOSE_ADDRESS_H + +#include "moose-prefix-address.h" +#include "moose-suffix-address.h" +#include "mac48-address.h" + +namespace ns3 { + +class Address; + +/** + * \ingroup address + * + * \brief a MOOSE (Multi-Level Object Orientated Ethernet) address + * + * This class can contain 48 bit MOOSE addresses. + */ +class MooseAddress +{ +public: + MooseAddress (); + MooseAddress (const char *str); + MooseAddress (const Mac48Address &mac); + + /** + * \returns true if this is a MOOSE address, false otherwise. + */ + + bool IsMoose() const; + + /** + * \returns the MOOSE prefix + */ + + const MoosePrefixAddress GetMoosePrefix() const; + + /** + * \returns the MOOSE prefix + */ + + const MooseSuffixAddress GetMooseSuffix() const; + + /** + * \returns the Mac48Address + */ + + const Mac48Address GetMacAddress() const; + + /** + * Allocate a new Moose Bridge Address. + */ + static MooseAddress Allocate (); + + /** + * Allocate a new Moose Host Address. + */ + static MooseAddress Allocate (MoosePrefixAddress prefix); + +private: + + uint8_t m_address[6]; + +}; + +} + +#endif + diff --git a/code/src/node/moose-prefix-address.cc b/code/src/node/moose-prefix-address.cc new file mode 100644 index 0000000..5c8503c --- /dev/null +++ b/code/src/node/moose-prefix-address.cc @@ -0,0 +1,41 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * + * 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: Richard Whitehouse + */ + +#include "moose-prefix-address.h" + +namespace ns3 { + +MoosePrefixAddress::MoosePrefixAddress (){ + memset (m_address, 0, 2); +} + +MoosePrefixAddress::MoosePrefixAddress(const uint8_t buffer[2]){ + memcpy(m_address, buffer, 2); +} + +const uint16_t MoosePrefixAddress::GetInt() const{ + uint16_t i; + i = m_address[0]; + i += m_address[1] << 8; + return i; +} + + +} diff --git a/code/src/node/moose-prefix-address.h b/code/src/node/moose-prefix-address.h new file mode 100644 index 0000000..df332d0 --- /dev/null +++ b/code/src/node/moose-prefix-address.h @@ -0,0 +1,72 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * + * 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: Richard Whitehouse + */ +#ifndef MOOSE_PREFIX_ADDRESS_H +#define MOOSE_PREFIX_ADDRESS_H + +#include +#include +#include + +namespace ns3 { + +class MoosePrefixAddress { + +public: + MoosePrefixAddress(); + MoosePrefixAddress(const uint8_t buffer[2]); + const uint16_t GetInt() const; + +private: + + uint8_t m_address[2]; + + friend bool operator < (const MoosePrefixAddress &a, const MoosePrefixAddress &b); + friend bool operator == (const MoosePrefixAddress &a, const MoosePrefixAddress &b); + friend bool operator != (const MoosePrefixAddress &a, const MoosePrefixAddress &b); + friend std::istream& operator>> (std::istream& is, MoosePrefixAddress & address); + + friend class MooseAddress; + +}; + +/** + * \class ns3::Mac48AddressValue + * \brief hold objects of type ns3::Mac48Address + */ + +inline bool operator == (const MoosePrefixAddress &a, const MoosePrefixAddress &b) +{ + return memcmp (a.m_address, b.m_address, 2) == 0; +} +inline bool operator != (const MoosePrefixAddress &a, const MoosePrefixAddress &b) +{ + return memcmp (a.m_address, b.m_address, 2) != 0; +} +inline bool operator < (const MoosePrefixAddress &a, const MoosePrefixAddress &b) +{ + return memcmp (a.m_address, b.m_address, 2) < 0; +} + +std::istream& operator>> (std::istream& is, MoosePrefixAddress & address); + +} // namespace ns3 + + +#endif diff --git a/code/src/node/moose-suffix-address.cc b/code/src/node/moose-suffix-address.cc new file mode 100644 index 0000000..49dc814 --- /dev/null +++ b/code/src/node/moose-suffix-address.cc @@ -0,0 +1,35 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * + * 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: Richard Whitehouse + */ + +#include "moose-suffix-address.h" + +namespace ns3 { + +MooseSuffixAddress::MooseSuffixAddress (){ + memset (m_address, 0, 6); +} + +MooseSuffixAddress::MooseSuffixAddress(const uint8_t buffer[3]){ + memcpy(m_address, buffer, 3); +} + + + +} diff --git a/code/src/node/moose-suffix-address.h b/code/src/node/moose-suffix-address.h new file mode 100644 index 0000000..6827101 --- /dev/null +++ b/code/src/node/moose-suffix-address.h @@ -0,0 +1,68 @@ +/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ +/* + * Copyright (c) 2007 INRIA + * + * 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: Richard Whitehouse + */ +#ifndef MOOSE_SUFFIX_ADDRESS_H +#define MOOSE_SUFFIX_ADDRESS_H + +#include +#include +#include + +namespace ns3 { + +class MooseSuffixAddress { + +public: + MooseSuffixAddress(); + MooseSuffixAddress(const uint8_t buffer[3]); + +private: + + uint8_t m_address[6]; + + friend bool operator < (const MooseSuffixAddress &a, const MooseSuffixAddress &b); + friend bool operator == (const MooseSuffixAddress &a, const MooseSuffixAddress &b); + friend bool operator != (const MooseSuffixAddress &a, const MooseSuffixAddress &b); + friend std::istream& operator>> (std::istream& is, MooseSuffixAddress & address); + +}; + +/** + * \class ns3::Mac48AddressValue + * \brief hold objects of type ns3::Mac48Address + */ + +inline bool operator == (const MooseSuffixAddress &a, const MooseSuffixAddress &b) +{ + return memcmp (a.m_address, b.m_address, 3) == 0; +} +inline bool operator != (const MooseSuffixAddress &a, const MooseSuffixAddress &b) +{ + return memcmp (a.m_address, b.m_address, 3) != 0; +} +inline bool operator < (const MooseSuffixAddress &a, const MooseSuffixAddress &b) +{ + return memcmp (a.m_address, b.m_address, 3) < 0; +} + +std::istream& operator>> (std::istream& is, MooseSuffixAddress & address); + +} // namespace ns3 + +#endif diff --git a/code/src/node/wscript b/code/src/node/wscript index 8c9764d..f8a0bfc 100644 --- a/code/src/node/wscript +++ b/code/src/node/wscript @@ -5,6 +5,9 @@ def build(bld): node.source = [ 'address.cc', 'mac48-address.cc', + 'moose-address.cc', + 'moose-prefix-address.cc', + 'moose-suffix-address.cc', 'mac64-address.cc', 'inet-socket-address.cc', 'packet-socket-address.cc', @@ -60,6 +63,9 @@ def build(bld): headers.source = [ 'address.h', 'mac48-address.h', + 'moose-address.h', + 'moose-prefix-address.h', + 'moose-suffix-address.h', 'mac64-address.h', 'inet-socket-address.h', 'packet-socket-address.h',