You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Omnet++ 5.5.1交换机配置:如何实现向特定节点定向发包而非广播

Configuring OMNeT++ 5.5.1 Switch to Send Packets to Specific Nodes

Hey there! Let’s fix that broadcast behavior and get your switch directing traffic only to specific nodes. I’ll assume you’re using the INET framework (the standard for network simulations in OMNeT++ 5.5.1)—if you’re working with a custom switch module, just let me know and I can adjust these steps.

Step 1: Set Up a Static MAC Address Table

By default, Ethernet switches broadcast packets when they don’t know the destination MAC’s port. To override this, define a static MAC-to-port mapping in your simulation’s .ini file. This tells the switch exactly where to send traffic for specific nodes.

Add this to your .ini configuration:

# Replace switch[*] with your switch module name if it's different
**.switch[*].macTable = {
    "00:00:00:00:00:01" : "port1",  # Map node1's MAC to switch port 1
    "00:00:00:00:00:02" : "port2"   # Map node2's MAC to switch port 2
}

Make sure the MAC addresses match the ones assigned to your target nodes (you can set these in the .ini too, see Step 3).

If your switch is set to dynamically learn MAC addresses, it might add new entries over time that could cause unintended broadcasts. To lock it to your static table:

**.switch[*].learning = false       # Turn off auto-learning of new MACs
**.switch[*].agingTime = 0s         # Prevent static entries from expiring

Step 3: Assign Fixed MAC Addresses to Target Nodes

To ensure your static mapping works, explicitly set MAC addresses for the nodes you want to target:

**.node1.eth[0].macAddress = "00:00:00:00:00:01"
**.node2.eth[0].macAddress = "00:00:00:00:00:02"

Step 4: Verify the Behavior

To confirm the switch isn’t broadcasting anymore, enable packet tracing in your .ini file:

**.packetDumper.dump = true

Run the simulation and check the trace output—you should see packets only going to the specified ports for your target nodes, not being sent to all ports.

For Custom Switch Modules

If you’re using a custom switch implementation instead of INET’s EthernetSwitch, you’ll need to modify the forwarding logic in your C++ code. Here’s a simplified example of how to direct packets to specific ports:

void MyCustomSwitch::handleMessage(cMessage *msg) {
    EthernetFrame *frame = check_and_cast<EthernetFrame *>(msg);
    MACAddress destAddr = frame->getDest();

    // Look up the port for the destination MAC
    std::string targetPort = getPortFromStaticTable(destAddr);

    if (!targetPort.empty()) {
        // Send only to the target port
        send(frame, targetPort.c_str());
    } else {
        // Optional: Drop the packet or broadcast if needed
        // broadcast(frame); // Remove this line to disable fallback broadcast
        delete frame;
    }
}

Just implement getPortFromStaticTable() to return the correct port for your target MACs.

内容的提问来源于stack exchange,提问作者Bhargav Kanumuri

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:40:26