25 auto macAddressInd = incomingPacket->getTag<MacAddressInd>();
26 auto sourceAddress = macAddressInd->getSrcAddress();
27 auto destinationAddress = macAddressInd->getDestAddress();
28 auto interfaceInd = incomingPacket->getTag<InterfaceInd>();
29 int incomingInterfaceId = interfaceInd->getInterfaceId();
30 auto incomingInterface =
interfaceTable->getInterfaceById(incomingInterfaceId);
31 unsigned int vlanId = 0;
32 if (
auto vlanInd = incomingPacket->findTag<VlanInd>())
33 vlanId = vlanInd->getVlanId();
34 EV_INFO <<
"Processing packet from network" <<
EV_FIELD(incomingInterface) <<
EV_FIELD(incomingPacket) <<
EV_ENDL;
37 auto outgoingPacket = incomingPacket->dup();
38 outgoingPacket->trim();
39 outgoingPacket->clearTags();
41 if (
auto vlanInd = incomingPacket->findTag<VlanInd>())
42 outgoingPacket->addTag<VlanReq>()->setVlanId(vlanInd->getVlanId());
43 if (
auto userPriorityInd = incomingPacket->findTag<UserPriorityInd>())
44 outgoingPacket->addTag<UserPriorityReq>()->setUserPriority(userPriorityInd->getUserPriority());
45 auto& macAddressReq = outgoingPacket->addTag<MacAddressReq>();
46 macAddressReq->setSrcAddress(sourceAddress);
47 macAddressReq->setDestAddress(destinationAddress);
48 if (destinationAddress.isBroadcast())
50 else if (destinationAddress.isMulticast()) {
51 auto outgoingInterfaceIds =
macForwardingTable->getMulticastAddressForwardingInterfaces(destinationAddress, vlanId);
52 if (outgoingInterfaceIds.size() == 0)
55 for (
auto outgoingInterfaceId : outgoingInterfaceIds) {
56 if (interfaceInd !=
nullptr && outgoingInterfaceId == interfaceInd->getInterfaceId())
57 EV_WARN <<
"Ignoring outgoing interface because it is the same as incoming interface" <<
EV_FIELD(destinationAddress) <<
EV_FIELD(incomingInterface) <<
EV_FIELD(incomingPacket) <<
EV_ENDL;
59 auto outgoingInterface =
interfaceTable->getInterfaceById(outgoingInterfaceId);
60 sendPacket(incomingPacket->dup(), destinationAddress, outgoingInterface);
63 delete incomingPacket;
69 int outgoingInterfaceId =
macForwardingTable->getUnicastAddressForwardingInterface(destinationAddress);
72 if (incomingInterfaceId == outgoingInterfaceId) {
73 EV_WARN <<
"Discarding packet because outgoing interface is the same as incoming interface" <<
EV_FIELD(destinationAddress) <<
EV_FIELD(incomingInterface) <<
EV_FIELD(incomingPacket) <<
EV_ENDL;
75 PacketDropDetails details;
78 delete outgoingPacket;
80 else if (outgoingInterfaceId != -1) {
81 auto outgoingInterface =
interfaceTable->getInterfaceById(outgoingInterfaceId);
82 sendPacket(outgoingPacket, destinationAddress, outgoingInterface);
89 delete incomingPacket;