Cleanup code, in theory finish mirror
Unclear: where / how to setup egress
This commit is contained in:
parent
06014333ee
commit
edd9624d29
2 changed files with 45 additions and 46 deletions
|
@ -1,33 +1,17 @@
|
||||||
#include <core.p4>
|
#include <core.p4>
|
||||||
#include <sume_switch.p4>
|
#include <sume_switch.p4>
|
||||||
|
|
||||||
/*
|
/********************************************************************************
|
||||||
Switch Calculator:
|
* Header
|
||||||
P4 program to use switch as a calculator and key-value lookup engine
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef bit<48> EthAddr_t;
|
typedef bit<48> EthAddr_t;
|
||||||
|
|
||||||
#define REG_READ 8w0
|
|
||||||
#define REG_WRITE 8w1
|
|
||||||
|
|
||||||
#define INDEX_WIDTH 4 // determines depth of const register
|
|
||||||
|
|
||||||
// define opCode types
|
|
||||||
#define ADD_OP 8w0
|
|
||||||
#define SUB_OP 8w1
|
|
||||||
#define LOOKUP_OP 8w2
|
|
||||||
#define ADD_REG_OP 8w3
|
|
||||||
#define SET_REG_OP 8w4
|
|
||||||
|
|
||||||
// standard Ethernet header
|
|
||||||
header Ethernet_h {
|
header Ethernet_h {
|
||||||
EthAddr_t dstAddr;
|
EthAddr_t dstAddr;
|
||||||
EthAddr_t srcAddr;
|
EthAddr_t srcAddr;
|
||||||
bit<16> etherType;
|
bit<16> etherType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// List of all recognized headers
|
|
||||||
struct Parsed_packet {
|
struct Parsed_packet {
|
||||||
Ethernet_h ethernet;
|
Ethernet_h ethernet;
|
||||||
}
|
}
|
||||||
|
@ -38,12 +22,16 @@ struct user_metadata_t {
|
||||||
bit<8> unused;
|
bit<8> unused;
|
||||||
}
|
}
|
||||||
|
|
||||||
// digest_data, MUST be 256 bits
|
// digest_data, MUST be 256 bits -- what is this used for?
|
||||||
struct digest_data_t {
|
struct digest_data_t {
|
||||||
bit<256> unused;
|
bit<256> unused;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parser Implementation
|
|
||||||
|
/********************************************************************************
|
||||||
|
* Parser
|
||||||
|
*/
|
||||||
|
|
||||||
@Xilinx_MaxPacketRegion(1024)
|
@Xilinx_MaxPacketRegion(1024)
|
||||||
parser TopParser(packet_in b,
|
parser TopParser(packet_in b,
|
||||||
out Parsed_packet p,
|
out Parsed_packet p,
|
||||||
|
@ -59,7 +47,9 @@ parser TopParser(packet_in b,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// match-action pipeline
|
/********************************************************************************
|
||||||
|
* Main
|
||||||
|
*/
|
||||||
control TopPipe(inout Parsed_packet p,
|
control TopPipe(inout Parsed_packet p,
|
||||||
inout user_metadata_t user_metadata,
|
inout user_metadata_t user_metadata,
|
||||||
inout digest_data_t digest_data,
|
inout digest_data_t digest_data,
|
||||||
|
@ -76,14 +66,16 @@ control TopPipe(inout Parsed_packet p,
|
||||||
}
|
}
|
||||||
|
|
||||||
table lookup_table {
|
table lookup_table {
|
||||||
key = { p.ethernet.dstAddr: exact; }
|
key = {
|
||||||
|
p.ethernet.dstAddr: exact;
|
||||||
|
}
|
||||||
|
|
||||||
actions = {
|
actions = {
|
||||||
swap_eth_addresses;
|
swap_eth_addresses;
|
||||||
do_nothing;
|
do_nothing;
|
||||||
}
|
}
|
||||||
size = 64;
|
size = 64;
|
||||||
default_action = do_nothing;
|
default_action = swap_eth_addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
apply {
|
apply {
|
||||||
|
@ -91,8 +83,10 @@ control TopPipe(inout Parsed_packet p,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/********************************************************************************
|
||||||
|
* Deparser
|
||||||
|
*/
|
||||||
|
|
||||||
// Deparser Implementation
|
|
||||||
@Xilinx_MaxPacketRegion(1024)
|
@Xilinx_MaxPacketRegion(1024)
|
||||||
control TopDeparser(packet_out b,
|
control TopDeparser(packet_out b,
|
||||||
in Parsed_packet p,
|
in Parsed_packet p,
|
||||||
|
@ -104,6 +98,12 @@ control TopDeparser(packet_out b,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/********************************************************************************
|
||||||
|
* Switch
|
||||||
|
*/
|
||||||
|
|
||||||
// Instantiate the switch
|
SimpleSumeSwitch(
|
||||||
SimpleSumeSwitch(TopParser(), TopPipe(), TopDeparser()) main;
|
TopParser(),
|
||||||
|
TopPipe(),
|
||||||
|
TopDeparser()
|
||||||
|
) main;
|
||||||
|
|
39
netpfga/minip4/testdata/gen_testdata.py
vendored
39
netpfga/minip4/testdata/gen_testdata.py
vendored
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env python
|
x3#!/usr/bin/env python
|
||||||
|
|
||||||
# from switch_calc_headers import *
|
# from switch_calc_headers import *
|
||||||
from scapy.all import *
|
from scapy.all import *
|
||||||
|
@ -116,26 +116,25 @@ def test_mirror():
|
||||||
pkt = pad_pkt(pkt, 64)
|
pkt = pad_pkt(pkt, 64)
|
||||||
expPkt(pkt, 'nf0')
|
expPkt(pkt, 'nf0')
|
||||||
|
|
||||||
# Second IP
|
# # Second IP
|
||||||
|
# pktCnt += 1
|
||||||
|
# pkt = Ether(dst=MAC2, src=MAC1) / IPv6(src="fe80::1", dst="fe80::2")
|
||||||
|
# pkt = pad_pkt(pkt, 64)
|
||||||
|
# applyPkt(pkt, 'nf0', pktCnt)
|
||||||
|
# pktCnt += 1
|
||||||
|
# pkt = Ether(dst=MAC1, src=MAC2) / IPv6(src="fe80::2", dst="fe80::1")
|
||||||
|
# pkt = pad_pkt(pkt, 64)
|
||||||
|
# expPkt(pkt, 'nf0')
|
||||||
|
|
||||||
pktCnt += 1
|
# # Third tcp
|
||||||
pkt = Ether(dst=MAC2, src=MAC1) / IPv6(src="fe80::1", dst="fe80::2")
|
# pktCnt += 1
|
||||||
pkt = pad_pkt(pkt, 64)
|
# pkt = Ether(dst=MAC2, src=MAC1) / IPv6(src="fe80::1", dst="fe80::2") / TCP(sport=42, dport=23)
|
||||||
applyPkt(pkt, 'nf0', pktCnt)
|
# pkt = pad_pkt(pkt, 64)
|
||||||
pktCnt += 1
|
# applyPkt(pkt, 'nf0', pktCnt)
|
||||||
pkt = Ether(dst=MAC1, src=MAC2) / IPv6(src="fe80::2", dst="fe80::1")
|
# pktCnt += 1
|
||||||
pkt = pad_pkt(pkt, 64)
|
# pkt = Ether(dst=MAC1, src=MAC2) / IPv6(src="fe80::2", dst="fe80::1") / TCP(sport=23, dport=42)
|
||||||
expPkt(pkt, 'nf0')
|
# pkt = pad_pkt(pkt, 64)
|
||||||
|
# expPkt(pkt, 'nf0')
|
||||||
# Third tcp
|
|
||||||
pktCnt += 1
|
|
||||||
pkt = Ether(dst=MAC2, src=MAC1) / IPv6(src="fe80::1", dst="fe80::2") / TCP(sport=42, dport=23)
|
|
||||||
pkt = pad_pkt(pkt, 64)
|
|
||||||
applyPkt(pkt, 'nf0', pktCnt)
|
|
||||||
pktCnt += 1
|
|
||||||
pkt = Ether(dst=MAC1, src=MAC2) / IPv6(src="fe80::2", dst="fe80::1") / TCP(sport=23, dport=42)
|
|
||||||
pkt = pad_pkt(pkt, 64)
|
|
||||||
expPkt(pkt, 'nf0')
|
|
||||||
|
|
||||||
test_mirror()
|
test_mirror()
|
||||||
write_pcap_files()
|
write_pcap_files()
|
||||||
|
|
Loading…
Reference in a new issue