Example #1
0
def main(inputfiles = []):
    OVSKernelSwitch.setup()
    net = Mininet(
        topo= GeneratedTopo(),
        switch=OVSKernelSwitch,
        build=False,
        link=TCLink,
        host=CPULimitedHost
    )
    c = RemoteController('c0', ip='127.0.0.1', port=6633)
    net.addController(c)
    net.build()
    net.start()
    #net.staticArp()
    
    num_h = len(net.hosts)
    p_start = -1
    count = 1
    ip_map = {}
    
    for f in inputfiles:
        print(f)
        with PcapReader(f) as pcap_reader:
            for pkt in pcap_reader:
                if IP not in pkt:
                    continue
                if pkt.src not in ip_map.keys():
                    ip_map[pkt.src] = net.nameToNode('h%d' % count) 
                    count = (count + 1) % num_h
                if pkt.dst not in ip_map.kesy():
                    ip_map[pkt.dst] = net.nameToNode('h%d' % count)
                    count = (count + 1) % num_h
                
                h = ip_map.get(pkt.src)
                pkt.src = h.IP()
                pkt.dst = ip_map.get(pkt.dst).IP()
                
                if pkt.src != pkt.dst:
                    thread.start_new_thread(ReadyToSend, (h, pkt, p_start))

    CLI( net )
    net.stop()