intrig-unicamp / mininet-wifi

Emulator for Software-Defined Wireless Networks
https://mn-wifi.readthedocs.io/
Other
431 stars 239 forks source link

why did sta2 also receive the data packets #523

Closed chenW0602 closed 5 months ago

chenW0602 commented 5 months ago

Hello! I'm a beginner. Now I have encountered some problems. To put it simply, why did sta2 also receive the data packets that were originally intended to be forwarded to other places? My network topology is as follows:

import sys
from mininet.node import Controller
from mininet.log import setLogLevel, info
from mn_wifi.link import wmediumd, _4address
from mn_wifi.cli import CLI
from mn_wifi.net import Mininet_wifi
from mn_wifi.wmediumdConnector import interference
from mininet.node import RemoteController

def topology():
    net=Mininet_wifi(controller=RemoteController)
    info("*** Creating nodes\n")
    ap1 = net.addAccessPoint('ap1', ssid="ap1-ssid", mode="g",channel="1", position='30,30,0',range=20)
    ap2 = net.addAccessPoint('ap2', ssid="ap2-ssid", mode="g",channel="2", position='50,30,0',range=20)
    ap3 = net.addAccessPoint('ap3', ssid="ap3-ssid", mode="g",channel="3", position='70,30,0',range=20)

    sta1 = net.addStation('sta1', ip="10.0.0.1/24", mac="00:00:00:00:00:01",position='20,20,0',range=20)
    sta2 = net.addStation('sta2', ip="10.0.0.2/24", mac="00:00:00:00:00:02",position='30,40,0',range=20)
    sta3 = net.addStation('sta3', ip="10.0.0.3/24", mac="00:00:00:00:00:03",position='50,20,0',range=20)
    sta4 = net.addStation('sta4', ip="10.0.0.4/24", mac="00:00:00:00:00:04",position='70,20,0',range=20)

    c0 = net.addController('c0', controller=RemoteController, ip='127.0.0.1', port=6633)

    info("*** Configuring Propagation Model\n")
    net.setPropagationModel(model="logDistance", exp=5)

    info("*** Configuring wifi nodes\n")
    net.configureWifiNodes()

    info("*** Adding Links\n")
    net.addLink(ap1,ap2,port1=10, port2=11)
    net.addLink(ap2,ap3, port1=12, port2=13)

    net.plotGraph(max_x=100, max_y=100)
    info('*** Starting network\n')
    net.build()
    c0.start()
    ap1.start([c0])
    ap2.start([c0])
    ap3.start([c0])

    sta1.setAssociation(ap1)
    sta2.setAssociation(ap1)
    sta3.setAssociation(ap2)
    sta4.setAssociation(ap3)
    info('*** Running CLI\n')
    CLI(net)
if __name__ == '__main__':
    setLogLevel('info')
    topology()

The network connection is as follows:

mininet-wifi> net
c0
sta1 sta1-wlan0:wifi
sta2 sta2-wlan0:wifi
sta3 sta3-wlan0:wifi
sta4 sta4-wlan0:wifi
ap1 lo:  ap1-wlan1:wifi ap1-eth10:ap2-eth11
ap2 lo:  ap2-wlan1:wifi ap2-eth11:ap1-eth10 ap2-eth12:ap3-eth13
ap3 lo:  ap3-wlan1:wifi ap3-eth13:ap2-eth12

Now add the flow table as follows liubiao

Start the receiving data packet code of sta2, the code is as follows:

from scapy.all import sniff, ICMP,IP,Raw
def packet_callback(packet):
    if ICMP in packet:
        icmp_packet = packet[ICMP]
        print("Received ICMP packet from h1.")
        if Raw in packet:
            raw_payload = packet[Raw].load.decode("utf-8")
            print(f"Payload: {raw_payload}")
sniff(iface="sta2-wlan0", prn=packet_callback, store=0)

Then let sta1 send a data packet, the code is as follows:

from scapy.all import Ether,IP, ICMP, send,Raw
packet = IP(src="10.0.0.1",dst='10.0.0.3')/ ICMP()/Raw(load="content 1")
send(packet,iface="sta1-wlan0")

Why did sta2 still receive this data packet? As shown below sta2

According to the flow table rules, shouldn't this packet be forwarded through port 10? I want to know which part of my code has the problem, or whether there is something in the forwarding mechanism of mininet-wifi that I have overlooked.

ramonfontes commented 5 months ago

Please consider using the mailing list for questions like that. We've discussed this subject a lot there.