|
INET Framework for OMNeT++/OMNEST
|
Management of IP tunnels.
More...
#include <Ipv6Tunneling.h>
|
| | Ipv6Tunneling () |
| |
| virtual void | initialize (int stage) override |
| | Initialize tunnel manager. More...
|
| |
| virtual int | numInitStages () const override |
| |
| virtual void | handleMessage (cMessage *msg) override |
| | Receive messages from Ipv6 module and encapsulate/decapsulate them. More...
|
| |
| int | createTunnel (TunnelType tunnelType, const Ipv6Address &src, const Ipv6Address &dest, const Ipv6Address &destTrigger=Ipv6Address::UNSPECIFIED_ADDRESS) |
| | Creates a tunnel with given entry and exit point, which will be used for datagrams destined for destTrigger. More...
|
| |
| bool | destroyTunnel (const Ipv6Address &src, const Ipv6Address &dest, const Ipv6Address &destTrigger) |
| | Creates a pseudo-tunnel for use with either Type 2 Routing Header or Home Address Option with given entry and exit point, which will be used for datagrams destined for destTrigger. More...
|
| |
| void | destroyTunnels (const Ipv6Address &entry) |
| | Remove all tunnels with provided entry point. More...
|
| |
| void | destroyTunnel (const Ipv6Address &entry, const Ipv6Address &exit) |
| | Remove the tunnel with the provided entry and exit point. More...
|
| |
| void | destroyTunnelForExitAndTrigger (const Ipv6Address &exit, const Ipv6Address &trigger) |
| | Remove the tunnel with the provided exit point and trigger. More...
|
| |
| void | destroyTunnelForEntryAndTrigger (const Ipv6Address &entry, const Ipv6Address &trigger) |
| | Remove the tunnel with the provided entry point and trigger. More...
|
| |
| void | destroyTunnelFromTrigger (const Ipv6Address &trigger) |
| | Remove the tunnel with the provided destination trigger. More...
|
| |
| int | getVIfIndexForDest (const Ipv6Address &destAddress) |
| | Returns the virtual interface identifier for the tunnel which has the provided destination as destination trigger. More...
|
| |
| virtual int | getVIfIndexForDest (const Ipv6Address &destAddress, TunnelType tunnelType) |
| | This method is equivalent for getVIfIndexForDest() except that it only searches for either "normal" or mobility tunnels. More...
|
| |
| bool | isTunnelExit (const Ipv6Address &exit) |
| | This method is equivalent for getVIfIndexForDest() except that it only searches for pseudo tunnels (T2RH, etc.). More...
|
| |
| virtual bool | handleOperationStage (LifecycleOperation *operation, IDoneCallback *doneCallback) override |
| | Perform one stage of a lifecycle operation. More...
|
| |
| virtual | ~ILifecycle () |
| |
|
| typedef std::map< int, struct Tunnel > | Tunnels |
| |
| typedef Tunnels::const_iterator | TI |
| |
|
| int | lookupTunnels (const Ipv6Address &dest) |
| | Search through all tunnels and locate one entry which is anything but a non-split tunnel and has a destination trigger for the provided address. More...
|
| |
| int | doPrefixMatch (const Ipv6Address &dest) |
| | Search through all tunnels and locate one entry which is a non-split tunnel (later on this could be exteded to searching for a tunnel that has a prefix matching the provided address). More...
|
| |
| void | resetVIfIndex () |
| | Reset the vIfIndex to its starting value if no tunnels exist anymore. More...
|
| |
Management of IP tunnels.
◆ TI
◆ Tunnels
◆ TunnelType
| Enumerator |
|---|
| INVALID | |
| SPLIT | |
| NON_SPLIT | |
| NORMAL | |
| T2RH | |
| HA_OPT | |
| MOBILITY | |
◆ Ipv6Tunneling()
| inet::Ipv6Tunneling::Ipv6Tunneling |
( |
| ) |
|
◆ createTunnel()
Creates a tunnel with given entry and exit point, which will be used for datagrams destined for destTrigger.
Type of tunnel (normal tunnel, mobility related pseudo-tunnel) is determined by first parameter. Returns virtual interface index.
107 &&
rt->isLocalAddress(entry) &&
rt->isLocalAddress(exit))
109 EV_INFO <<
"Cannot create tunnel with local endpoints (prevents loopback tunneling)" << endl;
113 int search =
findTunnel(entry, exit, destTrigger);
115 EV_INFO <<
"Tunnel with entry = " << entry <<
", exit = " << exit <<
" and trigger = "
116 << destTrigger <<
" already exists!" << endl;
121 throw cRuntimeError(
"Error: Not more than %d tunnels supported!", INT_MAX -
ift->getBiggestInterfaceId());
124 throw cRuntimeError(
"Error: Not more than 1 non-split tunnel supported!");
127 ASSERT(entry.isUnicast());
156 EV_INFO <<
"Tunneling: Created tunnel with entry=" << entry <<
", exit=" << exit
157 <<
" and trigger=" << destTrigger << endl;
159 else if (tunnelType ==
T2RH || tunnelType ==
HA_OPT) {
162 if (tunnelType ==
T2RH)
163 EV_INFO <<
"Tunneling: Created RH2 path with entry=" << entry <<
", exit=" << exit
164 <<
" and trigger=" << destTrigger << endl;
166 EV_INFO <<
"Tunneling: Created HA option path with entry=" << entry <<
", exit=" << exit
167 <<
" and trigger=" << destTrigger << endl;
170 throw cRuntimeError(
"tunnel type %d not supported for createTunnel()", tunnelType);
174 bubble(
"Created Tunnel");
Referenced by inet::Ipv6RoutingTable::configureTunnelFromXml().
◆ decapsulateDatagram()
| void inet::Ipv6Tunneling::decapsulateDatagram |
( |
Packet * |
packet | ) |
|
|
protected |
Strip tunnel headers from datagram.
465 auto ipv6Header = packet->peekAtFront<Ipv6Header>();
467 Ipv6Address srcAddr = packet->getTag<
L3AddressInd>()->getSrcAddress().toIpv6();
469 #ifdef INET_WITH_xMIPv6
484 EV_INFO <<
"Dropping packet: source address of tunnel IP header different from tunnel exit points!" << endl;
488 #endif // ifdef INET_WITH_xMIPv6
495 send(packet,
"linkLayerOut");
497 #ifdef INET_WITH_xMIPv6
500 NetworkInterface *ie =
ift->getInterfaceById(packet->getTag<InterfaceInd>()->getInterfaceId());
501 if (
rt->isMobileNode() && (srcAddr == ie->getProtocolData<Ipv6InterfaceData>()->getHomeAgentAddress())
504 EV_INFO <<
"Checking Route Optimization for: " << ipv6Header->getSrcAddress() << endl;
505 xMIPv6 *mipv6 = findModuleFromPar<xMIPv6>(par(
"xmipv6Module"),
this);
507 mipv6->triggerRouteOptimization(ipv6Header->getSrcAddress(), ie->getProtocolData<Ipv6InterfaceData>()->getMNHomeAddress(), ie);
509 #endif // ifdef INET_WITH_xMIPv6
Referenced by handleMessage().
◆ destroyTunnel() [1/2]
Remove the tunnel with the provided entry and exit point.
227 if (it->second.entry == entry && it->second.exit == exit) {
228 destroyTunnel(it->second.entry, it->second.exit, it->second.destTrigger);
◆ destroyTunnel() [2/2]
Creates a pseudo-tunnel for use with either Type 2 Routing Header or Home Address Option with given entry and exit point, which will be used for datagrams destined for destTrigger.
Returns virtual interface index. Remove tunnel and the associated entries from destination cache
196 EV_INFO <<
"Destroy tunnel entry =" << src <<
", exit = " << dest
197 <<
", destTrigger = " << destTrigger <<
"\n";
200 int vIfIndex =
findTunnel(src, dest, destTrigger);
203 EV_WARN <<
"Tunnel not found\n";
219 bubble(
"Destroyed Tunnel");
Referenced by destroyTunnel(), destroyTunnelForEntryAndTrigger(), destroyTunnelForExitAndTrigger(), destroyTunnelFromTrigger(), and destroyTunnels().
◆ destroyTunnelForEntryAndTrigger()
| void inet::Ipv6Tunneling::destroyTunnelForEntryAndTrigger |
( |
const Ipv6Address & |
entry, |
|
|
const Ipv6Address & |
trigger |
|
) |
| |
Remove the tunnel with the provided entry point and trigger.
257 if (it->second.entry == entry && it->second.destTrigger == trigger) {
258 destroyTunnel(it->second.entry, it->second.exit, it->second.destTrigger);
◆ destroyTunnelForExitAndTrigger()
| void inet::Ipv6Tunneling::destroyTunnelForExitAndTrigger |
( |
const Ipv6Address & |
exit, |
|
|
const Ipv6Address & |
trigger |
|
) |
| |
Remove the tunnel with the provided exit point and trigger.
242 if (it->second.exit == exit && it->second.destTrigger == trigger) {
243 destroyTunnel(it->second.entry, it->second.exit, it->second.destTrigger);
◆ destroyTunnelFromTrigger()
| void inet::Ipv6Tunneling::destroyTunnelFromTrigger |
( |
const Ipv6Address & |
trigger | ) |
|
Remove the tunnel with the provided destination trigger.
289 if (elem.second.destTrigger == trigger) {
290 destroyTunnel(elem.second.entry, elem.second.exit, elem.second.destTrigger);
◆ destroyTunnels()
| void inet::Ipv6Tunneling::destroyTunnels |
( |
const Ipv6Address & |
entry | ) |
|
Remove all tunnels with provided entry point.
272 if (it->second.entry == entry) {
276 destroyTunnel(oldIt->second.entry, oldIt->second.exit, oldIt->second.destTrigger);
◆ doPrefixMatch()
| int inet::Ipv6Tunneling::doPrefixMatch |
( |
const Ipv6Address & |
dest | ) |
|
|
private |
Search through all tunnels and locate one entry which is a non-split tunnel (later on this could be exteded to searching for a tunnel that has a prefix matching the provided address).
531 int outInterfaceId = -1;
536 if (elem.second.tunnelType ==
NON_SPLIT) {
537 outInterfaceId = elem.first;
542 return outInterfaceId;
Referenced by encapsulateDatagram(), and getVIfIndexForDest().
◆ encapsulateDatagram()
| void inet::Ipv6Tunneling::encapsulateDatagram |
( |
Packet * |
packet | ) |
|
|
protected |
Encapsulate a datagram with tunnel headers.
Attaches a Type 2 Routing Header in the control info if the datagram is routed over an appropriate RH2 pseudo tunnel.
351 auto ipv6Header = packet->peekAtFront<Ipv6Header>();
367 throw cRuntimeError(
"encapsulateDatagram(): tunnel not existent");
370 delete packet->removeControlInfo();
372 #ifdef INET_WITH_xMIPv6
377 Ipv6Address src = ipv6Header->getSrcAddress();
378 Ipv6Address dest = ipv6Header->getDestAddress();
381 if (src.isUnspecified()) {
385 (void)(
rt->lookupDestCache(dest, interfaceId));
392 rh2 =
tunnels[vIfIndex].destTrigger;
397 dest =
tunnels[vIfIndex].destTrigger;
402 packet->popAtFront<Ipv6Header>();
403 packet->addTagIfAbsent<
PacketProtocolTag>()->setProtocol(ipv6Header->getProtocol());
411 Ipv6RoutingHeader *t2RH =
new Ipv6RoutingHeader();
412 t2RH->setRoutingType(2);
413 t2RH->setSegmentsLeft(1);
414 t2RH->setAddressArraySize(1);
415 t2RH->setByteLength(
B(8 + 1 * 16));
417 t2RH->setAddress(0, rh2);
420 packet->addTagIfAbsent<Ipv6ExtHeaderReq>()->appendExtensionHeader(t2RH);
422 EV_INFO <<
"Added Type 2 Routing Header." << endl;
429 HomeAddressOption *haOpt =
new HomeAddressOption();
430 haOpt->setHomeAddress(rh2);
433 packet->addTagIfAbsent<Ipv6ExtHeaderReq>()->appendExtensionHeader(haOpt);
435 EV_INFO <<
"Added Home Address Option header." << endl;
438 auto addresses = packet->addTagIfAbsent<L3AddressReq>();
440 addresses->setSrcAddress(src);
442 addresses->setDestAddress(dest);
444 send(packet,
"upperLayerOut");
447 #endif // INET_WITH_xMIPv6
452 auto addresses = packet->addTagIfAbsent<L3AddressReq>();
453 addresses->setSrcAddress(
tunnels[vIfIndex].entry);
454 addresses->setDestAddress(
tunnels[vIfIndex].exit);
456 send(packet,
"upperLayerOut");
457 #ifdef INET_WITH_xMIPv6
460 #endif // ifdef INET_WITH_xMIPv6
Referenced by handleMessage().
◆ findTunnel()
Returns the type of the tunnels: non-split, split, T2RH, ...
Returns the vIfIndex of tunnel if found, 0 otherwise.
183 std::bind(equalTunnel(),
184 std::make_pair((
int)0, Tunnel(src, dest, destTrigger)),
185 std::placeholders::_1));
Referenced by createTunnel(), and destroyTunnel().
◆ getVIfIndexForDest() [1/2]
| int inet::Ipv6Tunneling::getVIfIndexForDest |
( |
const Ipv6Address & |
destAddress | ) |
|
Returns the virtual interface identifier for the tunnel which has the provided destination as destination trigger.
This is done by first looking at the split tunnels; if no split tunnels are found, a prefix matching on the non-split tunnels is then performed. In case both searches do not return a search hit, a value of -1 is returned.
303 EV_INFO <<
"Looking up tunnels...";
308 if (vIfIndex == -1) {
314 EV_DETAIL <<
"found vIf=" << vIfIndex << endl;
Referenced by encapsulateDatagram().
◆ getVIfIndexForDest() [2/2]
This method is equivalent for getVIfIndexForDest() except that it only searches for either "normal" or mobility tunnels.
321 int outInterfaceId = -1;
328 if ((elem.second.tunnelType ==
NON_SPLIT) ||
329 (elem.second.tunnelType ==
SPLIT && elem.second.destTrigger == destAddress))
331 outInterfaceId = elem.first;
336 if (elem.second.tunnelType !=
NON_SPLIT &&
337 elem.second.tunnelType !=
SPLIT &&
338 elem.second.destTrigger == destAddress)
340 outInterfaceId = elem.first;
346 return outInterfaceId;
◆ handleMessage()
| void inet::Ipv6Tunneling::handleMessage |
( |
cMessage * |
msg | ) |
|
|
overridevirtual |
Receive messages from Ipv6 module and encapsulate/decapsulate them.
79 Packet *packet = check_and_cast<Packet *>(msg);
81 if (packet->getArrivalGate()->isName(
"upperLayerIn")) {
85 else if (packet->getArrivalGate()->isName(
"linkLayerIn")) {
90 throw cRuntimeError(
"Ipv6Tunneling: Unknown gate: %s!", packet->getArrivalGate()->getFullName());
◆ initialize()
| void inet::Ipv6Tunneling::initialize |
( |
int |
stage | ) |
|
|
overridevirtual |
Initialize tunnel manager.
57 cSimpleModule::initialize(stage);
60 ift.reference(
this,
"interfaceTableModule",
true);
61 rt.reference(
this,
"routingTableModule",
true);
70 NodeStatus *nodeStatus = node ? check_and_cast_nullable<NodeStatus *>(node->getSubmodule(
"status")) : nullptr;
71 bool isOperational = (!nodeStatus) || nodeStatus->getState() ==
NodeStatus::UP;
73 throw cRuntimeError(
"This module doesn't support starting in node DOWN state");
◆ isTunnelExit()
| bool inet::Ipv6Tunneling::isTunnelExit |
( |
const Ipv6Address & |
exit | ) |
|
This method is equivalent for getVIfIndexForDest() except that it only searches for pseudo tunnels (T2RH, etc.).
Check if there exists a tunnel with exit equal to the provided address.
550 if (elem.second.tunnelType !=
T2RH && elem.second.tunnelType !=
HA_OPT
551 && elem.second.exit == exit)
Referenced by decapsulateDatagram().
◆ lookupTunnels()
| int inet::Ipv6Tunneling::lookupTunnels |
( |
const Ipv6Address & |
dest | ) |
|
|
private |
Search through all tunnels and locate one entry which is anything but a non-split tunnel and has a destination trigger for the provided address.
514 int outInterfaceId = -1;
520 if ((elem.second.tunnelType !=
NON_SPLIT) && (elem.second.destTrigger == dest)) {
521 outInterfaceId = elem.first;
526 return outInterfaceId;
Referenced by getVIfIndexForDest().
◆ numInitStages()
| virtual int inet::Ipv6Tunneling::numInitStages |
( |
| ) |
const |
|
inlineoverridevirtual |
◆ resetVIfIndex()
| void inet::Ipv6Tunneling::resetVIfIndex |
( |
| ) |
|
|
inlineprivate |
◆ operator<<
574 os <<
"tunnel entry = " << tun.entry <<
", exit = " << tun.exit <<
", tunnelMTU = "
575 << tun.tunnelMTU <<
", dest = " << tun.destTrigger <<
", type: ";
577 switch (tun.tunnelType) {
579 os <<
"split tunnel";
583 os <<
"non-split tunnel";
591 os <<
"Home Address Option path";
595 throw cRuntimeError(
"Not a valid type for an existing tunnel!");
◆ ift
◆ noOfNonSplitTunnels
| int inet::Ipv6Tunneling::noOfNonSplitTunnels = 0 |
|
protected |
◆ rt
◆ tunnels
| Tunnels inet::Ipv6Tunneling::tunnels |
|
protected |
Referenced by createTunnel(), destroyTunnel(), destroyTunnelForEntryAndTrigger(), destroyTunnelForExitAndTrigger(), destroyTunnelFromTrigger(), destroyTunnels(), doPrefixMatch(), encapsulateDatagram(), findTunnel(), getVIfIndexForDest(), initialize(), isTunnelExit(), and lookupTunnels().
◆ vIfIndexTop
| int inet::Ipv6Tunneling::vIfIndexTop = 0 |
|
protected |
The documentation for this class was generated from the following files:
cModule * findContainingNode(const cModule *from)
Find the node containing the given module.
Definition: ModuleAccess.cc:31
int doPrefixMatch(const Ipv6Address &dest)
Search through all tunnels and locate one entry which is a non-split tunnel (later on this could be e...
Definition: Ipv6Tunneling.cc:529
bool destroyTunnel(const Ipv6Address &src, const Ipv6Address &dest, const Ipv6Address &destTrigger)
Creates a pseudo-tunnel for use with either Type 2 Routing Header or Home Address Option with given e...
Definition: Ipv6Tunneling.cc:193
int lookupTunnels(const Ipv6Address &dest)
Search through all tunnels and locate one entry which is anything but a non-split tunnel and has a de...
Definition: Ipv6Tunneling.cc:512
static const Protocol ipv6
Definition: Protocol.h:94
@ MOBILITY
Definition: Ipv6Tunneling.h:47
INET_API InitStage INITSTAGE_NETWORK_LAYER
Initialization of network layer protocols.
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd L3AddressInd
Definition: IUdp-gates.txt:20
@ SPLIT
Definition: Ipv6Tunneling.h:42
@ T2RH
Definition: Ipv6Tunneling.h:45
int noOfNonSplitTunnels
Definition: Ipv6Tunneling.h:120
bool isTunnelExit(const Ipv6Address &exit)
This method is equivalent for getVIfIndexForDest() except that it only searches for pseudo tunnels (T...
Definition: Ipv6Tunneling.cc:545
removed DscpReq Ipv4ControlInfo Ipv6ControlInfo up L3AddressInd DispatchProtocolReq L4PortInd Ipv4ControlInfo Ipv6ControlInfo down PacketProtocolTag
Definition: IUdp-gates.txt:25
ModuleRefByPar< IInterfaceTable > ift
Definition: Ipv6Tunneling.h:51
@ HA_OPT
Definition: Ipv6Tunneling.h:46
@ INVALID
Definition: Ipv6Tunneling.h:41
intscale< b, 1, 8 > B
Definition: Units.h:1168
static const Ipv6Address UNSPECIFIED_ADDRESS
The unspecified address.
Definition: Ipv6Address.h:54
Tunnels tunnels
Definition: Ipv6Tunneling.h:114
INET_API InitStage INITSTAGE_LOCAL
Initialization of local state that don't use or affect other modules includes:
void decapsulateDatagram(Packet *packet)
Strip tunnel headers from datagram.
Definition: Ipv6Tunneling.cc:463
#define NUM_INIT_STAGES
Definition: InitStageRegistry.h:73
int getVIfIndexForDest(const Ipv6Address &destAddress)
Returns the virtual interface identifier for the tunnel which has the provided destination as destina...
Definition: Ipv6Tunneling.cc:300
int vIfIndexTop
Definition: Ipv6Tunneling.h:117
void resetVIfIndex()
Reset the vIfIndex to its starting value if no tunnels exist anymore.
Definition: Ipv6Tunneling.h:253
@ UP
Definition: NodeStatus.h:28
int findTunnel(const Ipv6Address &src, const Ipv6Address &dest, const Ipv6Address &destTrigger) const
Returns the type of the tunnels: non-split, split, T2RH, ...
Definition: Ipv6Tunneling.cc:179
#define IPv6_MIN_MTU
Definition: Ipv6InterfaceData.h:31
@ NORMAL
Definition: Ipv6Tunneling.h:44
void encapsulateDatagram(Packet *packet)
Encapsulate a datagram with tunnel headers.
Definition: Ipv6Tunneling.cc:349
#define IPv6__INET_DEFAULT_ROUTER_HOPLIMIT
Definition: Ipv6InterfaceData.h:37
@ IP_PROT_IPv6EXT_MOB
Definition: IpProtocolId_m.h:117
Tunnels::const_iterator TI
Definition: Ipv6Tunneling.h:102
ModuleRefByPar< Ipv6RoutingTable > rt
Definition: Ipv6Tunneling.h:52
@ NON_SPLIT
Definition: Ipv6Tunneling.h:43