diff --git a/Uebung1/Aufgabe1.3.mn b/Uebung1/Aufgabe1.3.mn index 67aa40d..5a47545 100644 --- a/Uebung1/Aufgabe1.3.mn +++ b/Uebung1/Aufgabe1.3.mn @@ -8,10 +8,10 @@ "nflowTimeout": "600" }, "openFlowVersions": { - "ovsOf10": "1", + "ovsOf10": "0", "ovsOf11": "0", "ovsOf12": "0", - "ovsOf13": "0" + "ovsOf13": "1" }, "sflow": { "sflowHeader": "128", @@ -19,7 +19,7 @@ "sflowSampling": "400", "sflowTarget": "" }, - "startCLI": "0", + "startCLI": "1", "switchType": "ovs", "terminalType": "xterm" }, @@ -27,7 +27,7 @@ { "opts": { "controllerProtocol": "tcp", - "controllerType": "ref", + "controllerType": "remote", "hostname": "c0", "remoteIP": "127.0.0.1", "remotePort": 6633 @@ -38,28 +38,16 @@ ], "hosts": [ { - "number": "1", + "number": "3", "opts": { - "defaultRoute": "10.0.1.14", - "hostname": "h1", - "ip": "10.0.1.1/28", - "nodeNum": 1, + "defaultRoute": "10.0.3.62", + "hostname": "h3", + "ip": "10.0.3.1/26", + "nodeNum": 3, "sched": "host" }, - "x": "452.0", - "y": "66.0" - }, - { - "number": "2", - "opts": { - "defaultRoute": "10.0.2.254", - "hostname": "h2", - "ip": "10.0.2.1/24", - "nodeNum": 2, - "sched": "host" - }, - "x": "300.0", - "y": "145.0" + "x": "754.0", + "y": "143.0" }, { "number": "4", @@ -74,16 +62,28 @@ "y": "444.0" }, { - "number": "3", + "number": "2", "opts": { - "defaultRoute": "10.0.3.62", - "hostname": "h3", - "ip": "10.0.3.1/26", - "nodeNum": 3, + "defaultRoute": "10.0.2.254", + "hostname": "h2", + "ip": "10.0.2.1/24", + "nodeNum": 2, "sched": "host" }, - "x": "754.0", - "y": "143.0" + "x": "300.0", + "y": "145.0" + }, + { + "number": "1", + "opts": { + "defaultRoute": "10.0.1.14", + "hostname": "h1", + "ip": "10.0.1.1/28", + "nodeNum": 1, + "sched": "host" + }, + "x": "452.0", + "y": "66.0" } ], "links": [ @@ -114,31 +114,39 @@ } ], "switches": [ - { - "number": "2", - "opts": { - "controllers": [ - "c0" - ], - "hostname": "s2", - "nodeNum": 2, - "switchType": "default" - }, - "x": "357.0", - "y": "300.0" - }, { "number": "1", "opts": { "controllers": [ "c0" ], + "dpid": "1", "hostname": "s1", + "netflow": "0", "nodeNum": 1, + "sflow": "0", + "switchIP": "", "switchType": "default" }, "x": "576.0", "y": "181.0" + }, + { + "number": "2", + "opts": { + "controllers": [ + "c0" + ], + "dpid": "2", + "hostname": "s2", + "netflow": "0", + "nodeNum": 2, + "sflow": "0", + "switchIP": "", + "switchType": "default" + }, + "x": "357.0", + "y": "300.0" } ], "version": "2" diff --git a/Uebung1/controller_1_3.py b/Uebung1/controller_1_3.py index d9e84c5..8012024 100644 --- a/Uebung1/controller_1_3.py +++ b/Uebung1/controller_1_3.py @@ -15,7 +15,7 @@ class L3Switch(app_manager.RyuApp): OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION] IP_ADDR = ["10.0.1.14", "10.0.2.254", "10.0.2.252", "10.0.3.62", "10.0.4.2"] - MAC_ADDR = "52:00:00:00:00:01" + MAC_ADDR = ["52:00:00:00:00:01", "52:00:00:00:00:02"] def __init__(self, *args, **kwargs): super(L3Switch, self).__init__(*args, **kwargs) @@ -40,6 +40,16 @@ class L3Switch(app_manager.RyuApp): ofproto.OFPCML_NO_BUFFER)] self.add_flow(datapath, 0, match, actions) + # Routing Switch 2 to 1 + actions = [parser.OFPActionDecNwTtl(), #decrease TTL count + parser.OFPActionSetField(eth_src=self.MAC_ADDR[1]), # set own mac as source + parser.OFPActionSetField(eth_dst=self.MAC_ADDR[0]), # set dst switch + parser.OFPActionOutput(1)] + + match = parser.OFPMatch(ipv4_src="10.0.4.0/30", ipv4_dst="0.0.0.0", eth_type=0x0800) + + self.add_flow(datapath, 0, match, actions) + def add_flow(self, datapath, priority, match, actions, buffer_id=None): ofproto = datapath.ofproto parser = datapath.ofproto_parser @@ -93,7 +103,7 @@ class L3Switch(app_manager.RyuApp): if arp_dstIp in self.IP_ADDR: # this switch was requested opcode = 2 - srcMAC = self.MAC_ADDR + srcMAC = self.MAC_ADDR[dpid-1] srcIP = arp_dstIp dstMAC = frame.src dstIP = arpPacket.src_ip @@ -128,7 +138,7 @@ class L3Switch(app_manager.RyuApp): self.logger.info("froward ARP request %s => %s (port%d)" %(srcMAC, dstMAC, outPort)) elif arpPacket.opcode == 2 : self.logger.info(arpPacket) - if arpPacket.dst_mac == self.MAC_ADDR: + if arpPacket.dst_mac in self.MAC_ADDR: # learn mac 2 port mapping self.mac_to_port[dpid][arpPacket.src_mac] = inPort # learn ip 2 mac mapping @@ -166,12 +176,13 @@ class L3Switch(app_manager.RyuApp): self.send_packet(datapath, outPort, p) def do_icmp(self, datapath, port, pkt_ethernet, pkt_ipv4, pkt_icmp): + dpid = datapath.id if pkt_icmp.type != icmp.ICMP_ECHO_REQUEST: return pkt = packet.Packet() pkt.add_protocol(ethernet.ethernet(ethertype=pkt_ethernet.ethertype, dst=pkt_ethernet.src, - src=self.MAC_ADDR)) + src=dpid)) pkt.add_protocol(ipv4.ipv4(dst=pkt_ipv4.src, src=pkt_ipv4.dst, proto=pkt_ipv4.proto)) @@ -225,12 +236,12 @@ class L3Switch(app_manager.RyuApp): # on the packet. out_port = ofproto.OFPP_FLOOD dstMac = "FF:FF:FF:FF:FF:FF" - self.send_arp(datapath, 1, self.MAC_ADDR, ipv4_pkt.src, dstMac, ipv4_pkt.dst, out_port) + self.send_arp(datapath, 1, self.MAC_ADDR[dpid-1], ipv4_pkt.src, dstMac, ipv4_pkt.dst, out_port) # Actions are applied in the same order as defined in the list. # OFPActionOutput terminates the chain. So this call should be the last action. actions = [parser.OFPActionDecNwTtl(), #decrease TTL count - parser.OFPActionSetField(eth_src=self.MAC_ADDR), # set own mac as source + parser.OFPActionSetField(eth_src=self.MAC_ADDR[1]), # set own mac as source parser.OFPActionSetField(eth_dst=dstMac), # set dst from arp request parser.OFPActionOutput(out_port)] # forward packet through out_port @@ -311,7 +322,7 @@ class L3Switch(app_manager.RyuApp): # packet is not for this switch, so do l2 switching - if dst != self.MAC_ADDR: + if dst != self.MAC_ADDR[dpid - 1]: self.do_l2_switch(datapath, dpid, pkt, eth, in_port, msg.buffer_id) return return