+notes -comment

This commit is contained in:
Nico Schottelius 2019-07-21 16:39:15 +02:00
commit d97864ffa7
2 changed files with 42 additions and 18 deletions

View file

@ -1,10 +1,14 @@
#!/usr/bin/env python
# from switch_calc_headers import *
from scapy.all import *
from nf_sim_tools import *
from collections import OrderedDict
import sss_sdnet_tuples
########################
# pkt generation tools #
########################
pktsApplied = []
pktsExpected = []
@ -39,11 +43,11 @@ nf_id_map = {
sss_sdnet_tuples.clear_tuple_files()
def applyPkt(pkt, ingress, time):
print("Applying pkt on {} at {}: ".format(ingress, time))
pktsApplied.append(pkt)
sss_sdnet_tuples.sume_tuple_in['src_port'] = nf_port_map[ingress]
sss_sdnet_tuples.sume_tuple_expect['src_port'] = nf_port_map[ingress]
pkt.time = time
print("apply packet on {} at {}: {}".format(ingress, time, pkt.__repr__()))
nf_applied[nf_id_map[ingress]].append(pkt)
def expPkt(pkt, egress):
@ -57,8 +61,6 @@ def expPkt(pkt, egress):
nf_expected[1].append(pkt)
nf_expected[2].append(pkt)
nf_expected[3].append(pkt)
print("exppkt packet on {}: {}".format(egress, pkt.__repr__()))
def print_summary(pkts):
for pkt in pkts:
@ -76,6 +78,7 @@ def write_pcap_files():
if (len(nf_expected[i]) > 0):
wrpcap('nf{0}_expected.pcap'.format(i), nf_expected[i])
# i = 0..3
for i in nf_applied.keys():
print "nf{0}_applied times: ".format(i), [p.time for p in nf_applied[i]]
@ -101,24 +104,22 @@ lookup_table = {
def test_port1():
""" packets for a certain mac always go to nf0 """
pktCnt = 0
pktCnt = 1
# First ethernet
pktCnt += 1
pkt = Ether(dst=MAC2, src=MAC1)
pkt = pad_pkt(pkt, 64)
applyPkt(pkt, 'nf0', pktCnt)
for inport in [ 'nf0', 'nf1', 'nf2', 'nf3' ]:
# Need to be regenerated, as object is modified above!
pkt = Ether(dst=MAC2, src=MAC1)
pkt = pad_pkt(pkt, 64)
pktCnt += 1
expPkt(pkt, 'nf0')
# Send on nf0..nf3
applyPkt(pkt, inport, pktCnt)
pktCnt += 1
applyPkt(pkt, 'nf1', pktCnt)
# Always receive on nf0 - also regenerate here!
pkt = Ether(dst=MAC2, src=MAC1)
pkt = pad_pkt(pkt, 64)
expPkt(pkt, 'nf0')
pktCnt += 1
expPkt(pkt, 'nf0')
pktCnt += 1
test_port1()
# don't write at the moment, just help debugging
# write_pcap_files()
write_pcap_files()