INET Framework for OMNeT++/OMNEST
inet::L3Address Class Reference

This class provides the generic interface for network addresses. More...

#include <L3Address.h>

Public Types

enum  AddressType {
  NONE, IPv4, IPv6, MAC,
  MODULEPATH, MODULEID
}
 

Public Member Functions

 L3Address ()
 
 L3Address (const char *str)
 
 L3Address (const IPv4Address &addr)
 
 L3Address (const IPv6Address &addr)
 
 L3Address (const MACAddress &addr)
 
 L3Address (const ModuleIdAddress &addr)
 
 L3Address (const ModulePathAddress &addr)
 
void set (const IPv4Address &addr)
 
void set (const IPv6Address &addr)
 
void set (const MACAddress &addr)
 
void set (const ModuleIdAddress &addr)
 
void set (const ModulePathAddress &addr)
 
IPv4Address toIPv4 () const
 
IPv6Address toIPv6 () const
 
MACAddress toMAC () const
 
ModuleIdAddress toModuleId () const
 
ModulePathAddress toModulePath () const
 
std::string str () const
 
AddressType getType () const
 
IL3AddressTypegetAddressType () const
 
L3Address getPrefix (int prefixLength) const
 Get the first prefixLength bits of the address, with the rest set to zero. More...
 
bool tryParse (const char *addr)
 
bool isUnspecified () const
 
bool isUnicast () const
 
bool isMulticast () const
 
bool isBroadcast () const
 
bool isLinkLocal () const
 
bool operator< (const L3Address &other) const
 
bool operator> (const L3Address &other) const
 
bool operator== (const L3Address &other) const
 
bool operator!= (const L3Address &other) const
 
bool matches (const L3Address &other, int prefixLength) const
 

Static Public Member Functions

static const char * getTypeName (AddressType t)
 

Private Member Functions

uint64 get (AddressType type) const
 
void set (AddressType type, uint64 lo)
 

Private Attributes

uint64 hi
 
uint64 lo
 

Detailed Description

This class provides the generic interface for network addresses.

For efficiency reasons the implementation uses a 128 bits integer to represent all kinds of network addresses. The different address implementations should not subclass this class, they should rather provide conversions to and from this class.

See also
IPv4Address, IPv6Address, MACAddress, ModulePathAddress, ModuleIdAddress

Member Enumeration Documentation

Enumerator
NONE 
IPv4 
IPv6 
MAC 
MODULEPATH 
MODULEID 
44  {
45  NONE,
46  IPv4,
47  IPv6,
48  MAC,
49  MODULEPATH,
50  MODULEID
51  };
Definition: L3Address.h:47
Definition: L3Address.h:49
Definition: L3Address.h:45
Definition: L3Address.h:50
Definition: L3Address.h:48
Definition: L3Address.h:46

Constructor & Destructor Documentation

inet::L3Address::L3Address ( )
inline

Referenced by getPrefix().

62 { set(NONE, 0); }
Definition: L3Address.h:45
inet::L3Address::L3Address ( const char *  str)
inlineexplicit
63 { tryParse(str); }
std::string str() const
Definition: L3Address.cc:86
bool tryParse(const char *addr)
Definition: L3Address.cc:112
inet::L3Address::L3Address ( const IPv4Address addr)
inline
64 { set(addr); }
inet::L3Address::L3Address ( const IPv6Address addr)
inline
65 { set(addr); }
inet::L3Address::L3Address ( const MACAddress addr)
inline
66 { set(addr); }
inet::L3Address::L3Address ( const ModuleIdAddress addr)
inline
67 { set(addr); }
inet::L3Address::L3Address ( const ModulePathAddress addr)
inline
68 { set(addr); }

Member Function Documentation

uint64 inet::L3Address::get ( AddressType  type) const
private

Referenced by inet::IPv4::arpResolutionTimedOut().

30 {
31  if (getType() == type)
32  return lo;
33  else
34  throw cRuntimeError("Address is not of the given type");
35 }
AddressType getType() const
Definition: L3Address.cc:52
uint64 lo
Definition: L3Address.h:55
IL3AddressType * inet::L3Address::getAddressType ( ) const

Referenced by inet::GPSR::computeOptionLength(), inet::ProbabilisticBroadcast::encapsMsg(), inet::Flood::encapsMsg(), inet::WiseRoute::getRoute(), inet::WiseRoute::handleSelfMessage(), inet::WiseRoute::handleUpperPacket(), inet::GPSR::initialize(), inet::dymo::DYMO::initialize(), inet::AODVRouting::initialize(), inet::AODVRouting::receiveSignal(), inet::dymo::DYMO::receiveSignal(), inet::sctp::SCTP::sendAbortFromMain(), inet::UDP::sendDown(), inet::IPvXTrafGen::sendPacket(), inet::PingApp::sendPing(), inet::sctp::SCTP::sendShutdownCompleteFromMain(), inet::tcp::TCPSpoof::sendToIP(), and inet::tcp::TCPConnection::sendToIP().

61 {
62  switch (getType()) {
63  case L3Address::NONE:
64  throw cRuntimeError("Address contains no value");
65 
66  case L3Address::IPv4:
68 
69  case L3Address::IPv6:
71 
72  case L3Address::MAC:
74 
77 
80 
81  default:
82  throw cRuntimeError("Unknown type");
83  }
84 }
AddressType getType() const
Definition: L3Address.cc:52
Definition: L3Address.h:47
Definition: L3Address.h:49
Definition: L3Address.h:45
static IPv6AddressType INSTANCE
Definition: IPv6AddressType.h:31
static MACAddressType INSTANCE
Definition: MACAddressType.h:31
static ModuleIdAddressType INSTANCE
Definition: ModuleIdAddressType.h:31
static ModulePathAddressType INSTANCE
Definition: ModulePathAddressType.h:31
static IPv4AddressType INSTANCE
Definition: IPv4AddressType.h:31
Definition: L3Address.h:50
Definition: L3Address.h:48
Definition: L3Address.h:46
L3Address inet::L3Address::getPrefix ( int  prefixLength) const

Get the first prefixLength bits of the address, with the rest set to zero.

359 {
360  switch (getType()) {
361  case L3Address::NONE:
362  return *this;
363 
364  case L3Address::IPv4:
365  return L3Address(toIPv4().getPrefix(prefixLength));
366 
367  case L3Address::IPv6:
368  return L3Address(toIPv6().getPrefix(prefixLength));
369 
370  case L3Address::MAC:
371  if (prefixLength != 48)
372  throw cRuntimeError("mask not supported for MACAddress");
373  return *this;
374 
375  case L3Address::MODULEID:
377  return *this;
378 
379  default:
380  throw cRuntimeError("getPrefix(): Unknown type");
381  }
382 }
AddressType getType() const
Definition: L3Address.cc:52
Definition: L3Address.h:47
L3Address()
Definition: L3Address.h:62
Definition: L3Address.h:49
Definition: L3Address.h:45
IPv6Address toIPv6() const
Definition: L3Address.h:77
L3Address getPrefix(int prefixLength) const
Get the first prefixLength bits of the address, with the rest set to zero.
Definition: L3Address.cc:358
Definition: L3Address.h:50
Definition: L3Address.h:48
IPv4Address toIPv4() const
Definition: L3Address.h:76
Definition: L3Address.h:46
L3Address::AddressType inet::L3Address::getType ( ) const

Referenced by inet::MultiFieldClassifier::addFilter(), inet::UDP::addMulticastAddressToInterface(), inet::IPv4::arpResolutionCompleted(), inet::IPv4::arpResolutionTimedOut(), inet::InterfaceEntry::changeMulticastGroupMembership(), inet::MultiFieldClassifier::configureFilters(), inet::serializer::SCTPSerializer::deserialize(), inet::sctp::SCTP::findAssocForInitAck(), inet::L3AddressResolver::findHostWithAddress(), inet::InterfaceTable::findInterfaceByAddress(), get(), inet::sctp::SCTPAssociation::getAddressLevel(), getAddressType(), getPrefix(), inet::GPSR::getSelfAddress(), isBroadcast(), isLinkLocal(), isMulticast(), inet::InterfaceTable::isNeighborAddress(), isUnicast(), isUnspecified(), inet::InterfaceEntry::joinMulticastGroup(), inet::GenericARP::mapUnicastAddress(), matches(), operator<(), operator==(), inet::UDP::processICMPError(), inet::sctp::SCTPAssociation::processInitAckArrived(), inet::sctp::SCTPAssociation::processInitArrived(), inet::PacketDump::sctpDump(), inet::sctp::SCTPAssociation::sendAsconf(), inet::UDP::sendDown(), inet::sctp::SCTPAssociation::sendInit(), set(), and str().

53 {
54  if (hi >> 48 == RESERVED_IPV6_ADDRESS_RANGE)
55  return (AddressType)(hi & 0xFF);
56  else
57  return L3Address::IPv6;
58 }
Definition: L3Address.h:47
AddressType
Definition: L3Address.h:44
#define RESERVED_IPV6_ADDRESS_RANGE
Definition: L3Address.cc:27
uint64 hi
Definition: L3Address.h:54
const char * inet::L3Address::getTypeName ( AddressType  t)
static

Referenced by inet::InterfaceEntry::changeMulticastGroupMembership(), and inet::L3AddressResolver::findHostWithAddress().

385 {
386 #define CASE(x) case x: \
387  return #x
388  switch (t) {
389  CASE(NONE);
390  CASE(IPv4);
391  CASE(IPv6);
392  CASE(MAC);
393  CASE(MODULEID);
394  CASE(MODULEPATH);
395 
396  default:
397  return "Unknown type";
398  }
399 #undef CASE
400 }
Definition: L3Address.h:47
Definition: L3Address.h:49
Definition: L3Address.h:45
#define CASE(x)
Definition: L3Address.h:50
Definition: L3Address.h:48
Definition: L3Address.h:46
bool inet::L3Address::isBroadcast ( ) const

Referenced by inet::AODVRouting::datagramForwardHook(), inet::GPSR::datagramLocalOutHook(), inet::GPSR::datagramPreRoutingHook(), inet::AODVRouting::ensureRouteForDatagram(), inet::dymo::DYMO::ensureRouteForDatagram(), inet::Flood::handleLowerPacket(), inet::WiseRoute::handleLowerPacket(), inet::WiseRoute::handleUpperPacket(), inet::dymo::DYMO::permissibleRteMsg(), inet::GenericARP::resolveL3Address(), and inet::AODVRouting::sendAODVPacket().

212 {
213  switch (getType()) {
214  case L3Address::NONE:
215  throw cRuntimeError("Address contains no value");
216 
217  case L3Address::IPv4:
219 
220  case L3Address::IPv6:
221  return false;
222 
223  //throw cRuntimeError("IPv6 isBroadcast() unimplemented");
224  case L3Address::MAC:
225  return toMAC().isBroadcast();
226 
227  case L3Address::MODULEID:
228  return toModuleId().isBroadcast();
229 
231  return toModulePath().isBroadcast();
232 
233  default:
234  throw cRuntimeError("Unknown type");
235  }
236 }
AddressType getType() const
Definition: L3Address.cc:52
bool isBroadcast() const
Returns true if this is the broadcast address (hex ff:ff:ff:ff:ff:ff).
Definition: MACAddress.h:141
Definition: L3Address.h:47
ModulePathAddress toModulePath() const
Definition: L3Address.h:80
Definition: L3Address.h:49
Definition: L3Address.h:45
bool isBroadcast() const
Definition: ModulePathAddress.h:48
ModuleIdAddress toModuleId() const
Definition: L3Address.h:79
bool isLimitedBroadcastAddress() const
Returns true if this address is the limited broadcast address, i.e.
Definition: IPv4Address.h:220
MACAddress toMAC() const
Definition: L3Address.h:78
Definition: L3Address.h:50
Definition: L3Address.h:48
bool isBroadcast() const
Definition: ModuleIdAddress.h:48
IPv4Address toIPv4() const
Definition: L3Address.h:76
Definition: L3Address.h:46
bool inet::L3Address::isLinkLocal ( ) const

Referenced by inet::RIPRouting::configureInitialRoutes(), and inet::RIPRouting::isValidResponse().

239 {
240  switch (getType()) {
241  case L3Address::NONE:
242  throw cRuntimeError("Address contains no value");
243 
244  case L3Address::IPv4:
245  return false;
246 
247  case L3Address::IPv6:
248  return toIPv6().isLinkLocal();
249 
250  case L3Address::MAC:
251  return true;
252 
253  case L3Address::MODULEID:
254  return false;
255 
257  return false;
258 
259  default:
260  throw cRuntimeError("Unknown type");
261  }
262 }
AddressType getType() const
Definition: L3Address.cc:52
Definition: L3Address.h:47
Definition: L3Address.h:49
Definition: L3Address.h:45
IPv6Address toIPv6() const
Definition: L3Address.h:77
bool isLinkLocal() const
Utility function based on getScope()
Definition: IPv6Address.h:298
Definition: L3Address.h:50
Definition: L3Address.h:48
Definition: L3Address.h:46
bool inet::L3Address::isMulticast ( ) const

Referenced by inet::UDP::addMulticastAddressToInterface(), inet::UDP::blockMulticastSources(), inet::RIPRouting::configureInitialRoutes(), inet::AODVRouting::datagramForwardHook(), inet::GenericNetworkProtocol::datagramLocalOut(), inet::GPSR::datagramLocalOutHook(), inet::GenericNetworkProtocol::datagramPreRouting(), inet::GPSR::datagramPreRoutingHook(), inet::AODVRouting::ensureRouteForDatagram(), inet::dymo::DYMO::ensureRouteForDatagram(), inet::L3AddressResolver::findHostWithAddress(), inet::GenericRoutingTable::isLocalMulticastAddress(), inet::UDP::joinMulticastGroups(), inet::UDP::joinMulticastSources(), inet::UDP::leaveMulticastSources(), inet::GenericARP::mapMulticastAddress(), inet::dymo::DYMO::permissibleRteMsg(), inet::UDP::processUDPPacket(), inet::GenericARP::resolveL3Address(), inet::RIPRouting::sendPacket(), inet::UDP::setMulticastSourceFilter(), inet::UDPSink::setSocketOptions(), and inet::UDP::unblockMulticastSources().

186 {
187  switch (getType()) {
188  case L3Address::NONE:
189  throw cRuntimeError("Address contains no value");
190 
191  case L3Address::IPv4:
192  return toIPv4().isMulticast();
193 
194  case L3Address::IPv6:
195  return toIPv6().isMulticast();
196 
197  case L3Address::MAC:
198  return toMAC().isMulticast();
199 
200  case L3Address::MODULEID:
201  return toModuleId().isMulticast();
202 
204  return toModulePath().isMulticast();
205 
206  default:
207  throw cRuntimeError("Unknown type");
208  }
209 }
AddressType getType() const
Definition: L3Address.cc:52
Definition: L3Address.h:47
ModulePathAddress toModulePath() const
Definition: L3Address.h:80
bool isMulticast() const
Definition: ModuleIdAddress.h:47
Definition: L3Address.h:49
bool isMulticast() const
Returns true if this address is in the multicast address range, 224.0.0.0 thru 239.255.255.255, that is, it&#39;s a class D address.
Definition: IPv4Address.h:226
Definition: L3Address.h:45
bool isMulticast() const
Definition: ModulePathAddress.h:47
IPv6Address toIPv6() const
Definition: L3Address.h:77
bool isMulticast() const
Utility function based on getScope()
Definition: IPv6Address.h:289
ModuleIdAddress toModuleId() const
Definition: L3Address.h:79
bool isMulticast() const
Returns true if this is a multicast logical address (first byte&#39;s lsb is 1).
Definition: MACAddress.h:146
MACAddress toMAC() const
Definition: L3Address.h:78
Definition: L3Address.h:50
Definition: L3Address.h:48
IPv4Address toIPv4() const
Definition: L3Address.h:76
Definition: L3Address.h:46
bool inet::L3Address::isUnicast ( ) const

Referenced by inet::RIPRouting::isValidResponse(), and inet::GenericARP::resolveL3Address().

160 {
161  switch (getType()) {
162  case L3Address::NONE:
163  throw cRuntimeError("Address contains no value");
164 
165  case L3Address::IPv4:
166  return !toIPv4().isMulticast() && !toIPv4().isLimitedBroadcastAddress(); // TODO: move to IPv4Address
167 
168  case L3Address::IPv6:
169  return toIPv6().isUnicast();
170 
171  case L3Address::MAC:
172  return !toMAC().isBroadcast() && !toMAC().isMulticast(); // TODO: move to MACAddress
173 
174  case L3Address::MODULEID:
175  return toModuleId().isUnicast();
176 
178  return toModulePath().isUnicast();
179 
180  default:
181  throw cRuntimeError("Unknown type");
182  }
183 }
AddressType getType() const
Definition: L3Address.cc:52
bool isBroadcast() const
Returns true if this is the broadcast address (hex ff:ff:ff:ff:ff:ff).
Definition: MACAddress.h:141
Definition: L3Address.h:47
ModulePathAddress toModulePath() const
Definition: L3Address.h:80
bool isUnicast() const
Utility function based on getScope()
Definition: IPv6Address.h:292
Definition: L3Address.h:49
bool isMulticast() const
Returns true if this address is in the multicast address range, 224.0.0.0 thru 239.255.255.255, that is, it&#39;s a class D address.
Definition: IPv4Address.h:226
Definition: L3Address.h:45
bool isUnicast() const
Definition: ModulePathAddress.h:46
IPv6Address toIPv6() const
Definition: L3Address.h:77
ModuleIdAddress toModuleId() const
Definition: L3Address.h:79
bool isMulticast() const
Returns true if this is a multicast logical address (first byte&#39;s lsb is 1).
Definition: MACAddress.h:146
bool isLimitedBroadcastAddress() const
Returns true if this address is the limited broadcast address, i.e.
Definition: IPv4Address.h:220
MACAddress toMAC() const
Definition: L3Address.h:78
bool isUnicast() const
Definition: ModuleIdAddress.h:46
Definition: L3Address.h:50
Definition: L3Address.h:48
IPv4Address toIPv4() const
Definition: L3Address.h:76
Definition: L3Address.h:46
bool inet::L3Address::isUnspecified ( ) const

Referenced by inet::MultiFieldClassifier::addFilter(), inet::sctp::SCTP::addLocalAddress(), inet::sctp::SCTP::addLocalAddressToAllRemoteAddresses(), inet::tcp::TCP::addSockPair(), inet::GenericNetworkConfigurator::addStaticRoutes(), inet::GenericRoutingTable::configureRouterId(), inet::TCPAppBase::connect(), inet::SCTPClient::connect(), inet::SCTPPeer::connect(), inet::UDPSocket::connect(), inet::UDP::connect(), inet::UDP::createSocket(), inet::GenericNetworkProtocol::encapsulate(), inet::AODVRouting::ensureRouteForDatagram(), inet::dymo::DYMO::ensureRouteForDatagram(), inet::UDP::findFirstSocketByLocalAddress(), inet::GPSR::findGreedyRoutingNextHop(), inet::L3AddressResolver::findHostWithAddress(), inet::InterfaceTable::findInterfaceByAddress(), inet::GPSR::findPerimeterRoutingNextHop(), inet::UDP::findSocketForUnicastPacket(), inet::UDP::findSocketsForMcastBcastPacket(), inet::InetPacketPrinter2::formatRIPPacket(), inet::IPvXTrafGen::handleMessage(), inet::PingApp::handleMessage(), inet::AODVRouting::handleRREP(), inet::GenericRoute::info(), inet::RIPRoute::info(), inet::InterfaceTable::isNeighborAddress(), inet::UDP::MulticastMembership::isSourceAllowed(), inet::dymo::DYMO::permissibleRteMsg(), inet::sctp::SCTPAssociation::process_ASSOCIATE(), inet::tcp::TCP_lwIP::process_OPEN_ACTIVE(), inet::tcp::TCP_NSC::process_OPEN_PASSIVE(), inet::sctp::SCTPAssociation::process_SEND(), inet::sctp::SCTPAssociation::processAsconfAckArrived(), inet::GPSR::processBeaconTimer(), inet::UDP::processPacketFromApp(), inet::RIPRouting::processResponse(), inet::UDPBasicApp::processStart(), inet::UDPSink::processStop(), inet::UDPVideoStreamCli::requestStream(), inet::GPSR::routeDatagram(), inet::GenericNetworkProtocol::routePacket(), inet::GenericNetworkProtocol::sendDatagramToOutput(), inet::UDP::sendDown(), inet::sctp::SCTPAssociation::sendInit(), inet::tcp::TCPConnection::sendSyn(), inet::SimpleVoIPSender::sendVoIPPacket(), inet::PositionTable::setPosition(), inet::UDPSink::setSocketOptions(), inet::NetPerfMeter::transmitFrame(), inet::L3AddressResolver::tryResolve(), and inet::WiseRoute::updateRouteTable().

134 {
135  switch (getType()) {
136  case L3Address::NONE:
137  return true;
138 
139  case L3Address::IPv4:
140  return toIPv4().isUnspecified();
141 
142  case L3Address::IPv6:
143  return toIPv6().isUnspecified();
144 
145  case L3Address::MAC:
146  return toMAC().isUnspecified();
147 
148  case L3Address::MODULEID:
149  return toModuleId().isUnspecified();
150 
152  return toModulePath().isUnspecified();
153 
154  default:
155  throw cRuntimeError("Unknown type");
156  }
157 }
AddressType getType() const
Definition: L3Address.cc:52
bool isUnspecified() const
True if all four address bytes are zero.
Definition: IPv4Address.h:176
Definition: L3Address.h:47
ModulePathAddress toModulePath() const
Definition: L3Address.h:80
bool isUnspecified() const
Returns true if all address bytes are zero.
Definition: MACAddress.h:151
Definition: L3Address.h:49
Definition: L3Address.h:45
IPv6Address toIPv6() const
Definition: L3Address.h:77
ModuleIdAddress toModuleId() const
Definition: L3Address.h:79
bool isUnspecified() const
Definition: ModuleIdAddress.h:45
bool isUnspecified() const
Definition: ModulePathAddress.h:45
MACAddress toMAC() const
Definition: L3Address.h:78
Definition: L3Address.h:50
Definition: L3Address.h:48
bool isUnspecified() const
Check if the IPv6 Address is undefined.
Definition: IPv6Address.h:286
IPv4Address toIPv4() const
Definition: L3Address.h:76
Definition: L3Address.h:46
bool inet::L3Address::matches ( const L3Address other,
int  prefixLength 
) const

Referenced by inet::GenericRoutingTable::findBestMatchingRoute().

333 {
334  switch (getType()) {
335  case L3Address::NONE:
336  throw cRuntimeError("Address contains no value");
337 
338  case L3Address::IPv4:
339  return IPv4Address::maskedAddrAreEqual(toIPv4(), other.toIPv4(), IPv4Address::makeNetmask(prefixLength)); //FIXME !!!!!
340 
341  case L3Address::IPv6:
342  return toIPv6().matches(other.toIPv6(), prefixLength);
343 
344  case L3Address::MAC:
345  return toMAC() == other.toMAC();
346 
347  case L3Address::MODULEID:
348  return toModuleId() == other.toModuleId();
349 
351  return ModulePathAddress::maskedAddrAreEqual(toModulePath(), other.toModulePath(), prefixLength);
352 
353  default:
354  throw cRuntimeError("Unknown type");
355  }
356 }
AddressType getType() const
Definition: L3Address.cc:52
static bool maskedAddrAreEqual(const IPv4Address &addr1, const IPv4Address &addr2, const IPv4Address &netmask)
Test if the masked addresses (ie the mask is applied to addr1 and addr2) are equal.
Definition: IPv4Address.cc:260
Definition: L3Address.h:47
static bool maskedAddrAreEqual(const ModulePathAddress &addr1, const ModulePathAddress &addr2, int prefixLength)
Definition: ModulePathAddress.h:67
ModulePathAddress toModulePath() const
Definition: L3Address.h:80
Definition: L3Address.h:49
Definition: L3Address.h:45
bool matches(const IPv6Address &prefix, int prefixLength) const
Returns true if the address matches the given prefix.
Definition: IPv6Address.cc:365
IPv6Address toIPv6() const
Definition: L3Address.h:77
ModuleIdAddress toModuleId() const
Definition: L3Address.h:79
MACAddress toMAC() const
Definition: L3Address.h:78
Definition: L3Address.h:50
static IPv4Address makeNetmask(int length)
Creates and returns a netmask with the given length.
Definition: IPv4Address.h:335
Definition: L3Address.h:48
IPv4Address toIPv4() const
Definition: L3Address.h:76
Definition: L3Address.h:46
bool inet::L3Address::operator!= ( const L3Address other) const
328 {
329  return !operator==(other);
330 }
bool operator==(const L3Address &other) const
Definition: L3Address.cc:296
bool inet::L3Address::operator< ( const L3Address other) const
265 {
266  AddressType type = getType();
267  AddressType otherType = other.getType();
268  if (type != otherType)
269  return type < otherType;
270  else {
271  switch (type) {
272  case L3Address::NONE:
273  throw cRuntimeError("Address contains no value");
274 
275  case L3Address::IPv4:
276  return toIPv4() < other.toIPv4();
277 
278  case L3Address::IPv6:
279  return toIPv6() < other.toIPv6();
280 
281  case L3Address::MAC:
282  return toMAC() < other.toMAC();
283 
284  case L3Address::MODULEID:
285  return toModuleId() < other.toModuleId();
286 
288  return toModulePath() < other.toModulePath();
289 
290  default:
291  throw cRuntimeError("Unknown type");
292  }
293  }
294 }
AddressType getType() const
Definition: L3Address.cc:52
Definition: L3Address.h:47
ModulePathAddress toModulePath() const
Definition: L3Address.h:80
Definition: L3Address.h:49
Definition: L3Address.h:45
IPv6Address toIPv6() const
Definition: L3Address.h:77
ModuleIdAddress toModuleId() const
Definition: L3Address.h:79
MACAddress toMAC() const
Definition: L3Address.h:78
Definition: L3Address.h:50
AddressType
Definition: L3Address.h:44
Definition: L3Address.h:48
IPv4Address toIPv4() const
Definition: L3Address.h:76
Definition: L3Address.h:46
bool inet::L3Address::operator== ( const L3Address other) const

Referenced by operator!=().

297 {
298  AddressType type = getType();
299  if (type != other.getType())
300  return false;
301  else {
302  switch (type) {
303  case L3Address::NONE:
304  return true;
305 
306  case L3Address::IPv4:
307  return toIPv4() == other.toIPv4();
308 
309  case L3Address::IPv6:
310  return toIPv6() == other.toIPv6();
311 
312  case L3Address::MAC:
313  return toMAC() == other.toMAC();
314 
315  case L3Address::MODULEID:
316  return toModuleId() == other.toModuleId();
317 
319  return toModulePath() == other.toModulePath();
320 
321  default:
322  throw cRuntimeError("Unknown type");
323  }
324  }
325 }
AddressType getType() const
Definition: L3Address.cc:52
Definition: L3Address.h:47
ModulePathAddress toModulePath() const
Definition: L3Address.h:80
Definition: L3Address.h:49
Definition: L3Address.h:45
IPv6Address toIPv6() const
Definition: L3Address.h:77
ModuleIdAddress toModuleId() const
Definition: L3Address.h:79
MACAddress toMAC() const
Definition: L3Address.h:78
Definition: L3Address.h:50
AddressType
Definition: L3Address.h:44
Definition: L3Address.h:48
IPv4Address toIPv4() const
Definition: L3Address.h:76
Definition: L3Address.h:46
bool inet::L3Address::operator> ( const L3Address other) const
inline
100 { return other < *this; };
void inet::L3Address::set ( AddressType  type,
uint64  lo 
)
private

Referenced by inet::tcp::TCP_NSC_Connection::connect(), inet::L3AddressResolver::getInterfaceIPv4Address(), inet::L3AddressResolver::getInterfaceIPv6Address(), inet::tcp::TCP_NSC::handleIpInputMessage(), inet::tcp::TCP_NSC_Connection::listen(), and inet::tcp::TCP_NSC::sendToIP().

38 {
39  this->hi = ((uint64)RESERVED_IPV6_ADDRESS_RANGE << 48) + (uint64)type;
40  this->lo = lo;
41 }
uint64 lo
Definition: L3Address.h:55
uint64_t uint64
Definition: Compat.h:28
#define RESERVED_IPV6_ADDRESS_RANGE
Definition: L3Address.cc:27
uint64 hi
Definition: L3Address.h:54
void inet::L3Address::set ( const IPv4Address addr)
inline
70 { set(IPv4, addr.getInt()); }
Definition: L3Address.h:46
void inet::L3Address::set ( const IPv6Address addr)
44 {
45  const uint32 *words = addr.words();
46  hi = ((uint64) * (words + 0) << 32) + *(words + 1);
47  lo = ((uint64) * (words + 2) << 32) + *(words + 3);
48  if (getType() != IPv6)
49  throw cRuntimeError("Cannot set IPv6 address");
50 }
AddressType getType() const
Definition: L3Address.cc:52
Definition: L3Address.h:47
uint64 lo
Definition: L3Address.h:55
uint64_t uint64
Definition: Compat.h:28
uint32_t uint32
Definition: Compat.h:30
uint64 hi
Definition: L3Address.h:54
void inet::L3Address::set ( const MACAddress addr)
inline
72 { set(MAC, addr.getInt()); }
Definition: L3Address.h:48
void inet::L3Address::set ( const ModuleIdAddress addr)
inline
73 { set(MODULEID, addr.getId()); }
Definition: L3Address.h:50
void inet::L3Address::set ( const ModulePathAddress addr)
inline
74 { set(MODULEPATH, addr.getId()); }
Definition: L3Address.h:49
std::string inet::L3Address::str ( ) const

Referenced by inet::tcp::TCP::addSockPair(), inet::UDP::bind(), inet::UDP::blockMulticastSources(), inet::tcp::TCP_NSC_Connection::connect(), inet::GenericNetworkProtocol::encapsulate(), inet::UDPSocket::getReceivedPacketInfo(), inet::tcp::TCP_NSC::initialize(), inet::UDP::joinMulticastGroups(), inet::UDP::joinMulticastSources(), inet::UDP::leaveMulticastSources(), inet::operator<<(), inet::utils::filters::MessageSourceAddrFilter::receiveSignal(), inet::RoutingTableRecorder::recordRouteChange(), inet::sctp::SCTP::removeAssociation(), inet::ARP::resolveL3Address(), inet::PacketDump::sctpDump(), inet::sctp::SCTPPathVariables::SCTPPathVariables(), inet::GenericNetworkProtocol::sendDatagramToOutput(), and inet::UDP::unblockMulticastSources().

87 {
88  switch (getType()) {
89  case L3Address::NONE:
90  return "<none>";
91 
92  case L3Address::IPv4:
93  return toIPv4().str();
94 
95  case L3Address::IPv6:
96  return toIPv6().str();
97 
98  case L3Address::MAC:
99  return toMAC().str();
100 
101  case L3Address::MODULEID:
102  return toModuleId().str();
103 
105  return toModulePath().str();
106 
107  default:
108  throw cRuntimeError("Unknown type");
109  }
110 }
AddressType getType() const
Definition: L3Address.cc:52
std::string str(bool printUnspec=true) const
Returns the string representation of the address (e.g.
Definition: IPv4Address.cc:109
Definition: L3Address.h:47
ModulePathAddress toModulePath() const
Definition: L3Address.h:80
Definition: L3Address.h:49
Definition: L3Address.h:45
IPv6Address toIPv6() const
Definition: L3Address.h:77
std::string str() const
Definition: ModuleIdAddress.h:68
ModuleIdAddress toModuleId() const
Definition: L3Address.h:79
std::string str() const
Converts address to a hex string.
Definition: MACAddress.cc:121
std::string str() const
Returns the textual representation of the address in the standard notation.
Definition: IPv6Address.cc:177
std::string str() const
Definition: ModulePathAddress.cc:70
MACAddress toMAC() const
Definition: L3Address.h:78
Definition: L3Address.h:50
Definition: L3Address.h:48
IPv4Address toIPv4() const
Definition: L3Address.h:76
Definition: L3Address.h:46
IPv4Address inet::L3Address::toIPv4 ( ) const
inline

Referenced by inet::UDP::addMulticastAddressToInterface(), inet::IPv4::arpResolutionCompleted(), inet::IPv4::arpResolutionTimedOut(), inet::InterfaceEntry::changeMulticastGroupMembership(), inet::IPv4::datagramForwardHook(), inet::IPv4::datagramLocalOutHook(), inet::IPv4::datagramPostRoutingHook(), inet::sctp::SCTPNatHook::datagramPreRoutingHook(), inet::IPv4::datagramPreRoutingHook(), inet::Define_Module(), inet::serializer::SCTPSerializer::deserialize(), inet::IPv4RoutingTable::findBestMatchingMulticastRoute(), inet::IPv4RoutingTable::findBestMatchingRoute(), inet::L3AddressResolver::findHostWithAddress(), inet::InterfaceTable::findInterfaceByAddress(), inet::IPv4::fragmentPostRouting(), inet::sctp::SCTPAssociation::getAddressLevel(), inet::IPv4RoutingTable::getInterfaceByAddress(), inet::IPv4RoutingTable::getNextHopForDestination(), inet::IPv4RoutingTable::getOutputInterfaceForDestination(), getPrefix(), inet::IPv4::handleIncomingDatagram(), inet::tcp::TCP_NSC::handleIpInputMessage(), inet::IPv4::handlePacketFromHL(), inet::ospf::ipv4AddressFromAddressString(), inet::ospf::ipv4NetmaskFromAddressString(), isBroadcast(), inet::IPv4RoutingTable::isLocalAddress(), inet::IPv4RoutingTable::isLocalMulticastAddress(), isMulticast(), inet::InterfaceTable::isNeighborAddress(), isUnicast(), isUnspecified(), inet::InterfaceEntry::joinMulticastGroup(), PacketDrill::makeIPPacket(), inet::tcp::TCP_NSC::mapRemote2Nsc(), matches(), operator<(), operator==(), inet::bgp::BGPRouting::processMessageFromTCP(), inet::LDP::processMessageFromTCP(), inet::ospf::HelloHandler::processPacket(), inet::IPv4NetworkConfigurator::readManualMulticastRouteConfiguration(), inet::IPv4NetworkConfigurator::readManualRouteConfiguration(), inet::IPv4NetworkConfigurator::resolveInterfaceAndGateway(), inet::GlobalARP::resolveL3Address(), inet::ARP::resolveL3Address(), inet::IPv4::routeUnicastPacket(), inet::UDP::sendDown(), inet::sctp::SCTPAssociation::sendInit(), inet::bgp::BGPSession::sendOpenMessage(), inet::IPv4Route::setDestination(), inet::IPv4ControlInfo::setDestinationAddress(), inet::IPv4Datagram::setDestinationAddress(), inet::IPv4MulticastRoute::setMulticastGroup(), inet::IPv4Route::setNextHop(), inet::IPv4MulticastRoute::setOrigin(), inet::IPv4ControlInfo::setSourceAddress(), inet::IPv4Datagram::setSourceAddress(), inet::DHCPServer::startApp(), and str().

76 { return getType() == NONE ? IPv4Address() : IPv4Address(get(IPv4)); }
AddressType getType() const
Definition: L3Address.cc:52
Definition: L3Address.h:45
uint64 get(AddressType type) const
Definition: L3Address.cc:29
Definition: L3Address.h:46
IPv6Address inet::L3Address::toIPv6 ( ) const
inline
MACAddress inet::L3Address::toMAC ( ) const
inline

Referenced by inet::InterfaceTable::findInterfaceByAddress(), isBroadcast(), isMulticast(), isUnicast(), isUnspecified(), inet::GenericARP::mapUnicastAddress(), matches(), operator<(), operator==(), and str().

78 { return getType() == NONE ? MACAddress() : MACAddress(get(MAC)); }
AddressType getType() const
Definition: L3Address.cc:52
Definition: L3Address.h:45
uint64 get(AddressType type) const
Definition: L3Address.cc:29
Definition: L3Address.h:48
ModulePathAddress inet::L3Address::toModulePath ( ) const
inline

Referenced by inet::InterfaceTable::findInterfaceByAddress(), isBroadcast(), isMulticast(), isUnicast(), isUnspecified(), inet::GenericARP::mapUnicastAddress(), matches(), operator<(), operator==(), and str().

80 { return getType() == NONE ? ModulePathAddress() : ModulePathAddress(get(MODULEPATH)); }
AddressType getType() const
Definition: L3Address.cc:52
Definition: L3Address.h:49
Definition: L3Address.h:45
uint64 get(AddressType type) const
Definition: L3Address.cc:29
bool inet::L3Address::tryParse ( const char *  addr)

Referenced by inet::L3AddressResolver::tryResolve().

113 {
114  IPv6Address ipv6;
115  MACAddress mac;
116  ModuleIdAddress moduleId;
117  ModulePathAddress modulePath;
118  if (IPv4Address::isWellFormed(addr))
119  set(IPv4Address(addr));
120  else if (ipv6.tryParse(addr))
121  set(ipv6);
122  else if (mac.tryParse(addr))
123  set(mac);
124  else if (moduleId.tryParse(addr))
125  set(moduleId);
126  else if (modulePath.tryParse(addr))
127  set(modulePath);
128  else
129  return false;
130  return true;
131 }
static bool isWellFormed(const char *text)
Returns true if the format of the string corresponds to an IPv4 address with the dotted notation ("19...
Definition: IPv4Address.cc:269

Member Data Documentation

uint64 inet::L3Address::hi
private

Referenced by getType(), and set().

uint64 inet::L3Address::lo
private

Referenced by get(), and set().


The documentation for this class was generated from the following files: