Set mac address based on destination network [HACK]

This commit is contained in:
Nico Schottelius 2019-04-03 11:31:29 +02:00
parent 2292f9e995
commit 0f2df2723b
3 changed files with 47 additions and 8 deletions

View file

@ -176,7 +176,17 @@
| 2019-04-03 | | | | 2019-04-03 | | |
| | ARP corrections -- ARP working for the switch! | x | | | ARP corrections -- ARP working for the switch! | x |
| | ICMP w/ incorrect checksum | x | | | ICMP w/ incorrect checksum | x |
| | ICMP w/ correct checksum - PING REPLIES!!! | | | | ICMP w/ correct checksum - PING REPLIES!!! | x |
| | Next: check / verify / translate nat46 | |
| | | |
| | | |
| 2019-04-04 | | |
| | Report [no meeting w/ Laurent] | |
| | | |
| | Added arp handling | |
| | Added icmp handling | |
| | Static | |
| | | |
| | | | | | | |
| 2019-04-04 | NAT64 1:1 table ICMP, ICMPv6 working | | | 2019-04-04 | NAT64 1:1 table ICMP, ICMPv6 working | |
| | Will need some switch local ip addresses | | | | Will need some switch local ip addresses | |
@ -694,9 +704,11 @@ INFO:main:unhandled reassambled=<Ether dst=00:00:0a:00:00:42 src=00:00:0a:00:00
According to Edgar this should not be seen anyway. According to Edgar this should not be seen anyway.
****** DONE Calculate ICMP checksum ****** DONE Calculate ICMP checksum
****** DONE Check field lengths ****** DONE Check field lengths
****** TODO Fix resolve / mac addresses -> ethernet is wrong!
***** TODO transform protocol specific: icmp -> icmp6 ***** TODO transform protocol specific: icmp -> icmp6
****** TODO Make switch answer IPv4 icmp echo request for ****** DONE Make switch answer IPv4 icmp echo request for
******* DONE Make switch respond to ARP ******* DONE Make switch respond to ARP
******* DONE Make switch respond to icmp echo request w/ correct checksum (2019-04-03)
**** TODO Add / check default route for v4 hosts **** TODO Add / check default route for v4 hosts
**** TODO Update p4c to avoid compiler bug **** TODO Update p4c to avoid compiler bug
***** TODO Updating p4c ***** TODO Updating p4c
@ -1773,6 +1785,13 @@ transparent / in network modification
Only the destination network is matched for deciding on NAT64, as Only the destination network is matched for deciding on NAT64, as
priority based double LPM is not supported. This limits a prefix to be priority based double LPM is not supported. This limits a prefix to be
used only in one network. used only in one network.
**** TODO No resolution of hardware addresses
- hardcoded ip --> mac addresses
Correct version:
Resolve mac address in controller, buffer packet, replay packet /
handle packet.
Only has to be set, when packets originate from the switch/controller.
*** References / Follow up *** References / Follow up
**** RFC 791 IPv4 https://tools.ietf.org/html/rfc791 **** RFC 791 IPv4 https://tools.ietf.org/html/rfc791
**** RFC 792 ICMP https://tools.ietf.org/html/rfc792 **** RFC 792 ICMP https://tools.ietf.org/html/rfc792

View file

@ -78,6 +78,7 @@ class L2Controller(object):
# https://en.wikipedia.org/wiki/Solicited-node_multicast_address # https://en.wikipedia.org/wiki/Solicited-node_multicast_address
self.info['ndp_multicast'] = ipaddress.ip_network("ff02::1:ff00:0/104") self.info['ndp_multicast'] = ipaddress.ip_network("ff02::1:ff00:0/104")
self.info['mac_base'] = "00:00:0a:00:00:0{}"
self.info['mac_addr'] = "00:00:0a:00:00:42" self.info['mac_addr'] = "00:00:0a:00:00:42"
self.info['mac_broadcast'] = "ff:ff:ff:ff:ff:ff" self.info['mac_broadcast'] = "ff:ff:ff:ff:ff:ff"
self.info['ipv6_link_local'] = ipaddress.ip_address("fe80::200:aff:fe00:42") self.info['ipv6_link_local'] = ipaddress.ip_address("fe80::200:aff:fe00:42")
@ -115,8 +116,9 @@ class L2Controller(object):
net = self.info['v6_gen'].next() net = self.info['v6_gen'].next()
self.v6_routes['base'].append({ self.v6_routes['base'].append({
"net": net, "net": net,
"port": port} "port": port,
) "mac": self.info['mac_base'].format(port)
})
self.ports.append(port) self.ports.append(port)
self.v6_routes['router'] = self.v6_routes['base'] self.v6_routes['router'] = self.v6_routes['base']
@ -131,8 +133,9 @@ class L2Controller(object):
net = self.info['v4_gen'].next() net = self.info['v4_gen'].next()
self.v4_routes['base'].append({ self.v4_routes['base'].append({
"net": net, "net": net,
"port": port} "port": port,
) "mac": self.info['mac_base'].format(port)
})
self.ports.append(port) self.ports.append(port)
self.v4_routes['router'] = self.v4_routes['base'] self.v4_routes['router'] = self.v4_routes['base']
@ -256,13 +259,23 @@ class L2Controller(object):
def fill_tables(self): def fill_tables(self):
self.controller.table_clear("v6_networks") self.controller.table_clear("v6_networks")
for v6route in self.v6_routes[self.mode]: for v6route in self.v6_routes[self.mode]:
self.controller.table_add("v6_networks", "set_egress_port", [str(v6route['net'])], [str(v6route['port'])]) #self.controller.table_add("v6_networks", "set_egress_port", [str(v6route['net'])], [str(v6route['port'])])
self.controller.table_add("v4_networks", "set_egress_port_and_mac",
[str(v6route['net'])],
[str(v6route['port']),
str(v6route['mac']),
])
self.controller.table_clear("v4_networks") self.controller.table_clear("v4_networks")
self.controller.table_clear("v4_arp") self.controller.table_clear("v4_arp")
self.controller.table_clear("v4_arp_egress") self.controller.table_clear("v4_arp_egress")
for v4route in self.v4_routes[self.mode]: for v4route in self.v4_routes[self.mode]:
self.controller.table_add("v4_networks", "set_egress_port", [str(v4route['net'])], [str(v4route['port'])]) # self.controller.table_add("v4_networks", "set_egress_port", [str(v4route['net'])], [str(v4route['port'])])
self.controller.table_add("v4_networks", "set_egress_port_and_mac",
[str(v4route['net'])],
[str(v4route['port']),
str(v4route['mac']),
])
# ARP support # ARP support
self.controller.table_add("v4_arp_egress", "set_egress_port", [str(v4route['net'])], [str(v4route['port'])]) self.controller.table_add("v4_arp_egress", "set_egress_port", [str(v4route['net'])], [str(v4route['port'])])

View file

@ -26,6 +26,11 @@ control MyIngress(inout headers hdr,
standard_metadata.egress_spec = out_port; standard_metadata.egress_spec = out_port;
} }
action set_egress_port_and_mac (port_t out_port, mac_addr_t mac_addr) {
hdr.ethernet.dst_addr = mac_addr;
standard_metadata.egress_spec = out_port;
}
action controller_reply(task_t task) { action controller_reply(task_t task) {
meta.task = task; meta.task = task;
meta.ingress_port = standard_metadata.ingress_port; meta.ingress_port = standard_metadata.ingress_port;
@ -425,6 +430,7 @@ Echo or Echo Reply Message
} }
actions = { actions = {
set_egress_port; set_egress_port;
set_egress_port_and_mac;
controller_debug; controller_debug;
controller_reply; controller_reply;
controller_debug_table_id; controller_debug_table_id;
@ -440,6 +446,7 @@ Echo or Echo Reply Message
} }
actions = { actions = {
set_egress_port; set_egress_port;
set_egress_port_and_mac;
controller_debug; controller_debug;
controller_debug_table_id; controller_debug_table_id;
NoAction; NoAction;