diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..296b2cc --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +support/ diff --git a/doc/plan.org b/doc/plan.org index 0eba721..857495d 100644 --- a/doc/plan.org +++ b/doc/plan.org @@ -6,6 +6,9 @@ | 2019-02-21 | Clarifications Ueli Maurer (Mentor) | x | | | Write mail / phone | x | | 2019-02-22 | Have all papers handed in | | +| 2019-02-28 | Meet Laurent #2 | | +| | - Parser for all protocols (udp,tcp,icmp,icmp6) | | +| | | | | | | | | 2019-02-22 | Have rough definition of tasks | | | 2019-03-01 | Feature list / priority list / roadmap clear | | @@ -47,10 +50,11 @@ *** DONE Get feature list of tayga *** DONE Setup P4 base / structure *** DONE Create minimal controller for populating tables -*** TODO Checkout egress setting +*** TODO Checkout / review egress settings *** TODO Implement ICMP <-> ICMP6 translation -**** TODO Parse icmp -**** TODO Parse icmpv6 +**** DONE Parse icmp +**** DONE Parse icmpv6 +**** TODO Add (static) egress configuration **** TODO Translate icmp <-> icmp6 **** TODO Create table entry for mapping v4->v6 [net] **** TODO Create table entry for mapping v6->v4 [net] @@ -114,6 +118,7 @@ user@T:~# iptables -t mangle -A PREROUTING \ *** P4 based implementation TBD **** General + - IPv6 subnet 2001:db8::/32 - IPv6 hosts are in 2001:db8:6::/64 - IPv6 default router (::/0) is 2001:db8:6::42/64 diff --git a/p4app/controller.py b/p4app/controller.py index ac597e3..f54e396 100644 --- a/p4app/controller.py +++ b/p4app/controller.py @@ -12,6 +12,9 @@ import sys import re import logging +import argparse +import ipaddress + logging.basicConfig() log = logging.getLogger("main") @@ -20,6 +23,18 @@ class L2Controller(object): self.init_boilerplate(sw_name) self.init() + self.modes = ['base'] + + # Network / egress + self.v6_routes = {} + self.v6_routes['base'] = [] + self.v6_routes['base'].append({ "net": "2001:db8:61::/64", "port": "1"}) + self.v6_routes['base'].append({ "net": "2001:db8:62::/64", "port": "2"}) + self.v4_routes = {} + self.v4_routes['base'] = [] + self.v4_routes['base'].append({ "net": "10.0.41.0/24", "port": "3"}) + self.v4_routes['base'].append({ "net": "10.0.42.0/24", "port": "4"}) + def init_boilerplate(self, sw_name): self.topo = Topology(db="topology.db") self.sw_name = sw_name @@ -31,6 +46,7 @@ class L2Controller(object): def init(self): self.controller.reset_state() self.fill_tables() + self.config_hosts() self.add_mirror() def add_mirror(self): @@ -38,6 +54,17 @@ class L2Controller(object): self.controller.mirroring_add(100, self.cpu_port) def fill_tables(self): + for v6route in self.v6_routes[self.mode]: + self.controller.table_add("v6_routing", "set_egress_port", [v6route['net']], [v6route['port']]) + + for v4route in self.v4_routes[self.mode]: + self.controller.table_add("v4_routing", "set_egress_port", [v4route['net']], [v4route['port']]) + + def config_hosts(self): + """ Assumptions: + - all routes are networks (no /128 v6 or /32 v4 + - hosts get the first ip address in the network + """ pass def debug_print_pkg(self, pkg, msg="INCOMING"): @@ -78,6 +105,13 @@ class L2Controller(object): def run_cpu_port_loop(self): sniff(iface=self.intf, prn=self.recv_msg_cpu) + def commandline(self): + parser = argparse.ArgumentParser(description='controller++') + parser.add_argument('--mode', help='Select mode / settings to use', choices=self.modes) + args = parser.parse_args() + self.mode = args.mode + + if __name__ == "__main__": import sys import os @@ -91,4 +125,7 @@ if __name__ == "__main__": log.debug("Debug enabled.") sw_name = "s1" - controller = L2Controller(sw_name).run_cpu_port_loop() + controller = L2Controller(sw_name) + + controller.commandline() + controller.run_cpu_port_loop() diff --git a/p4src/settings.p4 b/p4src/settings.p4 index 194843d..ac49a53 100644 --- a/p4src/settings.p4 +++ b/p4src/settings.p4 @@ -8,5 +8,6 @@ #define THE_ANSWER_TO_LIFE_THE_UNIVERSE_AND_EVERYTHING 42 +#define ROUTING_TABLE_SIZE = 64 /* maximum routes per protocol */ #endif diff --git a/p4src/static-mapping.p4 b/p4src/static-mapping.p4 index f81e36a..77c7602 100644 --- a/p4src/static-mapping.p4 +++ b/p4src/static-mapping.p4 @@ -13,11 +13,41 @@ *************************************************************************/ control MyIngress(inout headers hdr, - inout metadata meta, - inout standard_metadata_t standard_metadata) { + inout metadata meta, + inout standard_metadata_t standard_metadata) { + + /********************** ROUTING (egress definiton) TABLES ***********************************/ + action set_egress_port (port_t out_port) { + standard_metadata.egress_spec = out_port; + } + + table v6_routing { + key = { + hdr.ipv6.dst_addr: lpm; + } + actions = { + set_egress_port; + NoAction; + } + size = ROUTING_TABLE_SIZE; + default_action = NoAction; + } + + table v4_routing { + key = { + hdr.ipv4.dst_addr: lpm; + } + actions = { + set_egress_port; + NoAction; + } + size = ROUTING_TABLE_SIZE; + default_action = NoAction; + } apply { - + v6_routing.apply() + v4_routing.apply() } }