Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. dat-adi created this gist Dec 16, 2022.
    170 changes: 170 additions & 0 deletions heterogeneous_controller_triple_station_migration.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,170 @@
    #!/usr/bin/python
    """
    This is a script that emulates a triple controller
    heterogeneous environment, where mobile stations
    migrate from one AP range to another.
    """

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

    from subprocess import call
    from coordinates import rotate, find_points


    def migrateStation():
    "Creating the triple access point topology"
    net = Mininet_wifi(
    topo=None,
    build=False,
    link=wmediumd,
    wmediumd_mode=interference,
    )

    info("*** Adding controllers\n")
    c0 = net.addController(
    name="c0", controller=RemoteController, ip="192.168.0.122", protocols="tcp", port=6653
    )
    c1 = net.addController(
    name="c1", controller=RemoteController, ip="192.168.0.141", protocols="tcp", port=6653
    )
    c2 = net.addController(
    name="c2", controller=RemoteController, ip="192.168.0.217", protocols="tcp", port=6633
    )

    info("*** Setting up access points\n")
    ap1_coords = (300, 300, 0)
    ap2_coords = (1200, 300, 0)
    ap3_coords = (750, 750, 0)
    print("AP Coords")
    print(f"ap1: {ap1_coords}")
    print(f"ap2: {ap2_coords}")
    print(f"ap3: {ap3_coords}")

    ap1 = net.addAccessPoint(
    "ap1",
    ssid="ap1-ssid",
    mode="g",
    channel="1",
    position=f"{ap1_coords[0]},{ap1_coords[1]},{ap1_coords[2]}",
    )
    ap2 = net.addAccessPoint(
    "ap2",
    ssid="ap2-ssid",
    mode="g",
    channel="2",
    position=f"{ap2_coords[0]},{ap2_coords[1]},{ap2_coords[2]}",
    )
    ap3 = net.addAccessPoint(
    "ap3",
    ssid="ap3-ssid",
    mode="g",
    channel="3",
    position=f"{ap3_coords[0]},{ap3_coords[1]},{ap3_coords[2]}",
    )

    sta = []
    station_number = 0
    info("*** Creating stations\n")
    for point in find_points(ap1_coords, 3):
    sta.append(
    net.addStation(
    f"sta{station_number}",
    mac=f"00:00:00:00:00:0{station_number+1}",
    ip=f"192.168.0.{station_number+25}",
    position=f"{point[0]}, {point[1]}, {point[2]}",
    )
    )
    station_number += 1

    for point in find_points(ap2_coords, 3):
    sta.append(
    net.addStation(
    f"sta{station_number}",
    mac=f"00:00:00:00:00:0{station_number+1}",
    ip=f"192.168.0.{station_number+25}",
    position=f"{point[0]}, {point[1]}, {point[2]}",
    )
    )
    station_number += 1

    for point in find_points(ap3_coords, 3):
    sta.append(
    net.addStation(
    f"sta{station_number}",
    mac=f"00:00:00:00:00:0{station_number+1}",
    ip=f"192.168.0.{station_number+25}",
    position=f"{point[0]}, {point[1]}, {point[2]}",
    )
    )
    station_number += 1

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

    info("*** Configuring Wifi Nodes\n")
    net.configureWifiNodes()

    info("*** Creating links\n")
    for i in range(3):
    net.addLink(net.get("ap1"), sta[i])

    for i in range(3, 6):
    net.addLink(net.get("ap2"), sta[i])

    for i in range(6, 9):
    net.addLink(net.get("ap3"), sta[i])

    net.addLink(ap1, ap2)
    net.addLink(ap2, ap3)
    net.addLink(ap3, ap1)

    info("*** Setting up mobility scripts\n")
    p1, p2, p3, p4, p5, p6 = dict(), dict(), dict(), dict(), dict(), dict()
    p1 = {"position": f"{ap1_coords[0]-100}, {ap1_coords[1]-100}, 0"}
    p2 = {"position": f"{ap2_coords[0]+100}, {ap2_coords[1]+100}, 0"}
    p3 = {"position": f"{ap2_coords[0]-100}, {ap2_coords[1]-100}, 0"}
    p4 = {"position": f"{ap3_coords[0]+100}, {ap3_coords[1]+100}, 0"}
    p5 = {"position": f"{ap3_coords[0]-100}, {ap3_coords[1]-100}, 0"}
    p6 = {"position": f"{ap1_coords[0]+100}, {ap1_coords[1]+100}, 0"}

    for sta in net.stations:
    print(sta.position)

    net.startMobility(time=0, AC="ssf")
    net.mobility(net.stations[0], "start", time=1, **p1)
    net.mobility(net.stations[0], "stop", time=60, **p2)
    net.mobility(net.stations[4], "start", time=1, **p3)
    net.mobility(net.stations[4], "stop", time=60, **p4)
    net.mobility(net.stations[7], "start", time=1, **p5)
    net.mobility(net.stations[7], "stop", time=60, **p6)
    net.stopMobility(time=60)

    info("*** Plotting the graph\n")
    net.plotGraph(max_x=1500, max_y=1500)

    info("*** Starting network\n")
    net.build()

    info("*** Starting controllers\n")
    for controller in net.controllers:
    controller.start()
    net.get("ap1").start([c0, c1, c2])
    net.get("ap2").start([c0, c1, c2])
    net.get("ap3").start([c0, c1, c2])

    info("*** Running the CLI\n")
    CLI(net)

    info("*** Stopping network\n")
    net.staticArp()
    net.stop()


    if __name__ == "__main__":
    setLogLevel("info")
    migrateStation()