Begin to implement egress handling, make controller usable, update notes

This commit is contained in:
Nico Schottelius 2019-02-23 14:22:46 +01:00
parent 214ccd4479
commit bec7dc548e
5 changed files with 81 additions and 7 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
support/

View File

@ -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

View File

@ -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()

View File

@ -8,5 +8,6 @@
#define THE_ANSWER_TO_LIFE_THE_UNIVERSE_AND_EVERYTHING 42
#define ROUTING_TABLE_SIZE = 64 /* maximum routes per protocol */
#endif

View File

@ -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()
}
}