1.1 --- a/src/devices/csma/csma-net-device.cc Mon Aug 25 09:13:05 2008 -0700
1.2 +++ b/src/devices/csma/csma-net-device.cc Mon Aug 25 10:02:52 2008 -0700
1.3 @@ -670,27 +670,6 @@
1.4 NS_LOG_LOGIC ("Pkt source is " << header.GetSource ());
1.5 NS_LOG_LOGIC ("Pkt destination is " << header.GetDestination ());
1.6
1.7 - //
1.8 - // An IP host group address is mapped to an Ethernet multicast address
1.9 - // by placing the low-order 23-bits of the IP address into the low-order
1.10 - // 23 bits of the Ethernet multicast address 01-00-5E-00-00-00 (hex).
1.11 - //
1.12 - // We are going to receive all packets destined to any multicast address,
1.13 - // which means clearing the low-order 23 bits the header destination
1.14 - //
1.15 - Mac48Address mcDest;
1.16 - uint8_t mcBuf[6];
1.17 -
1.18 - header.GetDestination ().CopyTo (mcBuf);
1.19 - mcBuf[3] &= 0x80;
1.20 - mcBuf[4] = 0;
1.21 - mcBuf[5] = 0;
1.22 - mcDest.CopyFrom (mcBuf);
1.23 -
1.24 - Mac48Address multicast = Mac48Address::ConvertFrom (GetMulticast ());
1.25 - Mac48Address broadcast = Mac48Address::ConvertFrom (GetBroadcast ());
1.26 - Mac48Address destination = Mac48Address::ConvertFrom (GetAddress ());
1.27 -
1.28 if (m_receiveErrorModel && m_receiveErrorModel->IsCorrupt (packet) )
1.29 {
1.30 NS_LOG_LOGIC ("Dropping pkt due to error model ");
1.31 @@ -723,17 +702,17 @@
1.32
1.33 PacketType packetType;
1.34
1.35 - if (header.GetDestination () == broadcast)
1.36 + if (header.GetDestination ().IsBroadcast ())
1.37 {
1.38 packetType = PACKET_BROADCAST;
1.39 m_rxTrace (originalPacket);
1.40 }
1.41 - else if (mcDest == multicast)
1.42 + else if (header.GetDestination ().IsMulticast ())
1.43 {
1.44 packetType = PACKET_MULTICAST;
1.45 m_rxTrace (originalPacket);
1.46 }
1.47 - else if (header.GetDestination () == destination)
1.48 + else if (header.GetDestination () == m_address)
1.49 {
1.50 packetType = PACKET_HOST;
1.51 m_rxTrace (originalPacket);
1.52 @@ -855,65 +834,24 @@
1.53 CsmaNetDevice::GetMulticast (void) const
1.54 {
1.55 NS_LOG_FUNCTION_NOARGS ();
1.56 - return Mac48Address ("01:00:5e:00:00:00");
1.57 + return Mac48Address::GetMulticastPrefix ();
1.58 }
1.59
1.60 Address
1.61 CsmaNetDevice::MakeMulticastAddress (Ipv4Address multicastGroup) const
1.62 {
1.63 NS_LOG_FUNCTION (multicastGroup);
1.64 - //
1.65 - // First, get the generic multicast address.
1.66 - //
1.67 - Address hardwareDestination = GetMulticast ();
1.68
1.69 - NS_LOG_LOGIC ("Device multicast address: " << hardwareDestination);
1.70 -
1.71 - //
1.72 - // It's our address, and we know we're playing with an EUI-48 address here
1.73 - // primarily since we know that by construction, but also since the parameter
1.74 - // is an Ipv4Address.
1.75 - //
1.76 - Mac48Address etherAddr = Mac48Address::ConvertFrom (hardwareDestination);
1.77 -
1.78 - //
1.79 - // We now have the multicast address in an abstract 48-bit container. We
1.80 - // need to pull it out so we can play with it. When we're done, we have the
1.81 - // high order bits in etherBuffer[0], etc.
1.82 - //
1.83 - uint8_t etherBuffer[6];
1.84 - etherAddr.CopyTo (etherBuffer);
1.85 -
1.86 - //
1.87 - // Now we need to pull the raw bits out of the Ipv4 destination address.
1.88 - //
1.89 - uint8_t ipBuffer[4];
1.90 - multicastGroup.Serialize (ipBuffer);
1.91 -
1.92 - //
1.93 - // RFC 1112 says that an Ipv4 host group address is mapped to an EUI-48
1.94 - // multicast address by placing the low-order 23-bits of the IP address into
1.95 - // the low-order 23 bits of the Ethernet multicast address
1.96 - // 01-00-5E-00-00-00 (hex).
1.97 - //
1.98 - etherBuffer[3] |= ipBuffer[1] & 0x7f;
1.99 - etherBuffer[4] = ipBuffer[2];
1.100 - etherBuffer[5] = ipBuffer[3];
1.101 -
1.102 - //
1.103 - // Now, etherBuffer has the desired ethernet multicast address. We have to
1.104 - // suck these bits back into the Mac48Address,
1.105 - //
1.106 - etherAddr.CopyFrom (etherBuffer);
1.107 + Mac48Address ad = Mac48Address::GetMulticast (multicastGroup);
1.108
1.109 //
1.110 // Implicit conversion (operator Address ()) is defined for Mac48Address, so
1.111 // use it by just returning the EUI-48 address which is automagically converted
1.112 // to an Address.
1.113 //
1.114 - NS_LOG_LOGIC ("multicast address is " << etherAddr);
1.115 + NS_LOG_LOGIC ("multicast address is " << ad);
1.116
1.117 - return etherAddr;
1.118 + return ad;
1.119 }
1.120
1.121 bool
2.1 --- a/src/devices/wifi/wifi-net-device.cc Mon Aug 25 09:13:05 2008 -0700
2.2 +++ b/src/devices/wifi/wifi-net-device.cc Mon Aug 25 10:02:52 2008 -0700
2.3 @@ -255,12 +255,12 @@
2.4 Address
2.5 WifiNetDevice::GetMulticast (void) const
2.6 {
2.7 - return Mac48Address ("01:00:5e:00:00:00");
2.8 + return Mac48Address::GetMulticastPrefix ();
2.9 }
2.10 Address
2.11 WifiNetDevice::MakeMulticastAddress (Ipv4Address multicastGroup) const
2.12 {
2.13 - return GetMulticast ();
2.14 + return Mac48Address::GetMulticast (multicastGroup);
2.15 }
2.16 bool
2.17 WifiNetDevice::IsPointToPoint (void) const
3.1 --- a/src/node/mac48-address.cc Mon Aug 25 09:13:05 2008 -0700
3.2 +++ b/src/node/mac48-address.cc Mon Aug 25 10:02:52 2008 -0700
3.3 @@ -144,6 +144,18 @@
3.4 bool
3.5 Mac48Address::IsMulticast (void) const
3.6 {
3.7 + uint8_t mcBuf[6];
3.8 + CopyTo (mcBuf);
3.9 + mcBuf[3] &= 0x80;
3.10 + mcBuf[4] = 0;
3.11 + mcBuf[5] = 0;
3.12 + Mac48Address prefix;
3.13 + prefix.CopyFrom (mcBuf);
3.14 + return prefix == Mac48Address::GetMulticastPrefix ();
3.15 +}
3.16 +bool
3.17 +Mac48Address::IsGroup (void) const
3.18 +{
3.19 return (m_address[0] & 0x01) == 0x01;
3.20 }
3.21 Mac48Address
3.22 @@ -152,6 +164,48 @@
3.23 static Mac48Address broadcast = Mac48Address ("ff:ff:ff:ff:ff:ff");
3.24 return broadcast;
3.25 }
3.26 +Mac48Address
3.27 +Mac48Address::GetMulticastPrefix (void)
3.28 +{
3.29 + static Mac48Address multicast = Mac48Address ("01:00:5e:00:00:00");
3.30 + return multicast;
3.31 +}
3.32 +Mac48Address
3.33 +Mac48Address::GetMulticast (Ipv4Address multicastGroup)
3.34 +{
3.35 + Mac48Address etherAddr = Mac48Address::GetMulticastPrefix ();
3.36 + //
3.37 + // We now have the multicast address in an abstract 48-bit container. We
3.38 + // need to pull it out so we can play with it. When we're done, we have the
3.39 + // high order bits in etherBuffer[0], etc.
3.40 + //
3.41 + uint8_t etherBuffer[6];
3.42 + etherAddr.CopyTo (etherBuffer);
3.43 +
3.44 + //
3.45 + // Now we need to pull the raw bits out of the Ipv4 destination address.
3.46 + //
3.47 + uint8_t ipBuffer[4];
3.48 + multicastGroup.Serialize (ipBuffer);
3.49 +
3.50 + //
3.51 + // RFC 1112 says that an Ipv4 host group address is mapped to an EUI-48
3.52 + // multicast address by placing the low-order 23-bits of the IP address into
3.53 + // the low-order 23 bits of the Ethernet multicast address
3.54 + // 01-00-5E-00-00-00 (hex).
3.55 + //
3.56 + etherBuffer[3] |= ipBuffer[1] & 0x7f;
3.57 + etherBuffer[4] = ipBuffer[2];
3.58 + etherBuffer[5] = ipBuffer[3];
3.59 +
3.60 + //
3.61 + // Now, etherBuffer has the desired ethernet multicast address. We have to
3.62 + // suck these bits back into the Mac48Address,
3.63 + //
3.64 + Mac48Address result;
3.65 + result.CopyFrom (etherBuffer);
3.66 + return result;
3.67 +}
3.68
3.69 bool operator == (const Mac48Address &a, const Mac48Address &b)
3.70 {
4.1 --- a/src/node/mac48-address.h Mon Aug 25 09:13:05 2008 -0700
4.2 +++ b/src/node/mac48-address.h Mon Aug 25 10:02:52 2008 -0700
4.3 @@ -24,6 +24,7 @@
4.4 #include <ostream>
4.5 #include "ns3/attribute.h"
4.6 #include "ns3/attribute-helper.h"
4.7 +#include "ipv4-address.h"
4.8
4.9 namespace ns3 {
4.10
4.11 @@ -92,12 +93,25 @@
4.12 * \returns true if this is a multicast address, false otherwise.
4.13 */
4.14 bool IsMulticast (void) const;
4.15 + /**
4.16 + * \returns true if the group bit is set, false otherwise.
4.17 + */
4.18 + bool IsGroup (void) const;
4.19
4.20 /**
4.21 * \returns the broadcast address
4.22 */
4.23 static Mac48Address GetBroadcast (void);
4.24
4.25 + /**
4.26 + * \returns a multicast address
4.27 + */
4.28 + static Mac48Address GetMulticast (Ipv4Address address);
4.29 +
4.30 + /**
4.31 + * \returns the multicast prefix (01:00:5e:00:00:00).
4.32 + */
4.33 + static Mac48Address GetMulticastPrefix (void);
4.34 private:
4.35 /**
4.36 * \returns a new Address instance
5.1 --- a/src/node/simple-net-device.cc Mon Aug 25 09:13:05 2008 -0700
5.2 +++ b/src/node/simple-net-device.cc Mon Aug 25 10:02:52 2008 -0700
5.3 @@ -142,12 +142,12 @@
5.4 Address
5.5 SimpleNetDevice::GetMulticast (void) const
5.6 {
5.7 - return Mac48Address ("01:00:5e:00:00:00");
5.8 + return Mac48Address::GetMulticastPrefix ();
5.9 }
5.10 Address
5.11 SimpleNetDevice::MakeMulticastAddress (Ipv4Address multicastGroup) const
5.12 {
5.13 - return Mac48Address ("01:00:5e:00:00:00");
5.14 + return Mac48Address::GetMulticast (multicastGroup);
5.15 }
5.16 bool
5.17 SimpleNetDevice::IsPointToPoint (void) const