Use types for signalling expected action

This commit is contained in:
Nico Schottelius 2019-03-04 16:23:28 +01:00
parent da7fda57bf
commit ea1873c14c
4 changed files with 33 additions and 12 deletions

View File

@ -27,7 +27,10 @@ log = logging.getLogger("main")
class CpuHeader(Packet):
name = 'CpuPacket'
fields_desc = [BitField('ingress_port', 0, 16)]
fields_desc = [
BitField('task',0,8)
BitField('ingress_port', 0, 16)
]
class L2Controller(object):
@ -35,6 +38,12 @@ class L2Controller(object):
# Command line mapping
self.modes = ['base', 'router']
self.task = {
'ICMP6_NS': 1,
'ICMP6_GENERAL': 2,
'DEBUG': 3
}
self.info={}
self.info['ndp_multicast'] = ipaddress.ip_network("ff02::1:ff00:0/104")
@ -158,8 +167,8 @@ class L2Controller(object):
for v6addr in self.v6_addresses[self.mode]:
icmp6_addr = self.gen_ndp_multicast_addr(v6addr)
self.controller.table_add("v6_addresses", "controller_reply", [str(v6addr)])
self.controller.table_add("v6_addresses", "controller_reply", [str(icmp6_addr)])
self.controller.table_add("v6_addresses", "controller_reply", [str(self.task['ICMP6_GENERAL'])], [str(v6addr)])
self.controller.table_add("v6_addresses", "controller_reply", [str(self.task['ICMP6_NS'])], [str(icmp6_addr)])
def config_hosts(self):
""" Assumptions:

View File

@ -8,8 +8,9 @@
typedef bit<48> mac_addr_t;
typedef bit<32> ipv4_addr_t;
typedef bit<128> ipv6_addr_t;
typedef bit<9> port_t;
typedef bit<9> port_t;
typedef bit<16> mcast_t;
typedef bit<8> task_t;
const bit<16> TYPE_IPV4 = 0x0800;
@ -31,6 +32,10 @@ const bit<8> ICMP6_NS = 135;
const bit<8> ICMP6_NA = 136;
const task_t TASK_ICMP6_NS = 1;
const task_t TASK_ICMP6_GENERAL = 2;
const task_t TASK_DEBUG = 3;
header ethernet_t {
mac_addr_t dst_addr;
@ -106,6 +111,10 @@ header icmp_t {
bit<32> rest;
}
header cpu_t {
port_t ingress_port;
task_t task;
}
struct headers {
ethernet_t ethernet;
@ -115,12 +124,11 @@ struct headers {
udp_t udp;
icmp6_t icmp6;
icmp_t icmp;
cpu_t cpu;
}
struct metadata {
bit<16> tcp_length;
bit<16> ethertype; /* we use this, if we are cloning */
bit<1> ether_modified;
task_t task;
}
#endif

View File

@ -75,6 +75,10 @@ parser MyParser(packet_in packet,
control MyDeparser(packet_out packet, in headers hdr) {
apply {
/* only if information is sent to the controller */
packet.emit(hdr.cpu);
/* always */
packet.emit(hdr.ethernet);
/* either */

View File

@ -27,12 +27,12 @@ control MyIngress(inout headers hdr,
}
action controller_debug() {
meta.ether_modified = 1;
meta.ethertype = TYPE_DEBUG;
meta.task = TASK_DEBUG;
clone3(CloneType.I2E, 100, meta);
}
action controller_reply() {
action controller_reply(task_t task) {
meta.task = task;
clone3(CloneType.I2E, 100, meta);
}
@ -203,7 +203,8 @@ control MyEgress(inout headers hdr,
apply {
// ingress clone
if (standard_metadata.instance_type == 1 && meta.ether_modified == 1){
hdr.ethernet.ethertype = meta.ethertype;
hdr.cpu.setValid();
hdr.cpu.task = meta.task;
}
}
}
@ -226,7 +227,6 @@ MyDeparser()
// hdr.tcp.setValid();
// hdr.cpu.setValid();
// hdr.cpu.srcAddr = hdr.ethernet.srcAddr;
// hdr.cpu.ingress_port = (bit<16>)meta.ingress_port;