use Mac48Address::GetMulticast to avoid code duplication
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Tue Sep 02 11:39:26 2008 -0700 (17 months ago)
changeset 35850404af4cacf0
parent 3584 4eb48239b4dc
child 3586 692e616413a3
child 3596 6c39b712a535
use Mac48Address::GetMulticast to avoid code duplication
src/devices/bridge/bridge-net-device.cc
     1.1 --- a/src/devices/bridge/bridge-net-device.cc	Tue Sep 02 11:28:03 2008 -0700
     1.2 +++ b/src/devices/bridge/bridge-net-device.cc	Tue Sep 02 11:39:26 2008 -0700
     1.3 @@ -302,52 +302,8 @@
     1.4  BridgeNetDevice::MakeMulticastAddress (Ipv4Address multicastGroup) const
     1.5  {
     1.6   NS_LOG_FUNCTION (this << multicastGroup);
     1.7 -//
     1.8 -// First, get the generic multicast address.
     1.9 -//
    1.10 -  Address hardwareDestination = GetMulticast ();
    1.11 -
    1.12 -  NS_LOG_LOGIC ("Device multicast address: " << hardwareDestination);
    1.13 -//
    1.14 -// It's our address, and we know we're playing with an EUI-48 address here
    1.15 -// primarily since we know that by construction, but also since the parameter
    1.16 -// is an Ipv4Address.
    1.17 -//
    1.18 -  Mac48Address etherAddr = Mac48Address::ConvertFrom (hardwareDestination);
    1.19 -//
    1.20 -// We now have the multicast address in an abstract 48-bit container.  We 
    1.21 -// need to pull it out so we can play with it.  When we're done, we have the 
    1.22 -// high order bits in etherBuffer[0], etc.
    1.23 -//
    1.24 -  uint8_t etherBuffer[6];
    1.25 -  etherAddr.CopyTo (etherBuffer);
    1.26 -//
    1.27 -// Now we need to pull the raw bits out of the Ipv4 destination address.
    1.28 -//
    1.29 -  uint8_t ipBuffer[4];
    1.30 -  multicastGroup.Serialize (ipBuffer);
    1.31 -//
    1.32 -// RFC 1112 says that an Ipv4 host group address is mapped to an EUI-48
    1.33 -// multicast address by placing the low-order 23-bits of the IP address into 
    1.34 -// the low-order 23 bits of the Ethernet multicast address 
    1.35 -// 01-00-5E-00-00-00 (hex). 
    1.36 -//
    1.37 -  etherBuffer[3] |= ipBuffer[1] & 0x7f;
    1.38 -  etherBuffer[4] = ipBuffer[2];
    1.39 -  etherBuffer[5] = ipBuffer[3];
    1.40 -//
    1.41 -// Now, etherBuffer has the desired ethernet multicast address.  We have to
    1.42 -// suck these bits back into the Mac48Address,
    1.43 -//
    1.44 -  etherAddr.CopyFrom (etherBuffer);
    1.45 -//
    1.46 -// Implicit conversion (operator Address ()) is defined for Mac48Address, so
    1.47 -// use it by just returning the EUI-48 address which is automagically converted
    1.48 -// to an Address.
    1.49 -//
    1.50 -  NS_LOG_LOGIC ("multicast address is " << etherAddr);
    1.51 -
    1.52 -  return etherAddr;
    1.53 + Mac48Address multicast = Mac48Address::GetMulticast (multicastGroup);
    1.54 + return multicast;
    1.55  }
    1.56  
    1.57