Update Aufgabe1.3

This commit is contained in:
2022-05-21 23:37:49 +00:00
parent 83d7aac0c7
commit ade625fdb9
2 changed files with 69 additions and 50 deletions

View File

@@ -8,10 +8,10 @@
"nflowTimeout": "600" "nflowTimeout": "600"
}, },
"openFlowVersions": { "openFlowVersions": {
"ovsOf10": "1", "ovsOf10": "0",
"ovsOf11": "0", "ovsOf11": "0",
"ovsOf12": "0", "ovsOf12": "0",
"ovsOf13": "0" "ovsOf13": "1"
}, },
"sflow": { "sflow": {
"sflowHeader": "128", "sflowHeader": "128",
@@ -19,7 +19,7 @@
"sflowSampling": "400", "sflowSampling": "400",
"sflowTarget": "" "sflowTarget": ""
}, },
"startCLI": "0", "startCLI": "1",
"switchType": "ovs", "switchType": "ovs",
"terminalType": "xterm" "terminalType": "xterm"
}, },
@@ -27,7 +27,7 @@
{ {
"opts": { "opts": {
"controllerProtocol": "tcp", "controllerProtocol": "tcp",
"controllerType": "ref", "controllerType": "remote",
"hostname": "c0", "hostname": "c0",
"remoteIP": "127.0.0.1", "remoteIP": "127.0.0.1",
"remotePort": 6633 "remotePort": 6633
@@ -38,28 +38,16 @@
], ],
"hosts": [ "hosts": [
{ {
"number": "1", "number": "3",
"opts": { "opts": {
"defaultRoute": "10.0.1.14", "defaultRoute": "10.0.3.62",
"hostname": "h1", "hostname": "h3",
"ip": "10.0.1.1/28", "ip": "10.0.3.1/26",
"nodeNum": 1, "nodeNum": 3,
"sched": "host" "sched": "host"
}, },
"x": "452.0", "x": "754.0",
"y": "66.0" "y": "143.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"
}, },
{ {
"number": "4", "number": "4",
@@ -74,16 +62,28 @@
"y": "444.0" "y": "444.0"
}, },
{ {
"number": "3", "number": "2",
"opts": { "opts": {
"defaultRoute": "10.0.3.62", "defaultRoute": "10.0.2.254",
"hostname": "h3", "hostname": "h2",
"ip": "10.0.3.1/26", "ip": "10.0.2.1/24",
"nodeNum": 3, "nodeNum": 2,
"sched": "host" "sched": "host"
}, },
"x": "754.0", "x": "300.0",
"y": "143.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": [ "links": [
@@ -114,31 +114,39 @@
} }
], ],
"switches": [ "switches": [
{
"number": "2",
"opts": {
"controllers": [
"c0"
],
"hostname": "s2",
"nodeNum": 2,
"switchType": "default"
},
"x": "357.0",
"y": "300.0"
},
{ {
"number": "1", "number": "1",
"opts": { "opts": {
"controllers": [ "controllers": [
"c0" "c0"
], ],
"dpid": "1",
"hostname": "s1", "hostname": "s1",
"netflow": "0",
"nodeNum": 1, "nodeNum": 1,
"sflow": "0",
"switchIP": "",
"switchType": "default" "switchType": "default"
}, },
"x": "576.0", "x": "576.0",
"y": "181.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" "version": "2"

View File

@@ -15,7 +15,7 @@ class L3Switch(app_manager.RyuApp):
OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION] 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"] 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): def __init__(self, *args, **kwargs):
super(L3Switch, self).__init__(*args, **kwargs) super(L3Switch, self).__init__(*args, **kwargs)
@@ -40,6 +40,16 @@ class L3Switch(app_manager.RyuApp):
ofproto.OFPCML_NO_BUFFER)] ofproto.OFPCML_NO_BUFFER)]
self.add_flow(datapath, 0, match, actions) 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): def add_flow(self, datapath, priority, match, actions, buffer_id=None):
ofproto = datapath.ofproto ofproto = datapath.ofproto
parser = datapath.ofproto_parser parser = datapath.ofproto_parser
@@ -93,7 +103,7 @@ class L3Switch(app_manager.RyuApp):
if arp_dstIp in self.IP_ADDR: if arp_dstIp in self.IP_ADDR:
# this switch was requested # this switch was requested
opcode = 2 opcode = 2
srcMAC = self.MAC_ADDR srcMAC = self.MAC_ADDR[dpid-1]
srcIP = arp_dstIp srcIP = arp_dstIp
dstMAC = frame.src dstMAC = frame.src
dstIP = arpPacket.src_ip 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)) self.logger.info("froward ARP request %s => %s (port%d)" %(srcMAC, dstMAC, outPort))
elif arpPacket.opcode == 2 : elif arpPacket.opcode == 2 :
self.logger.info(arpPacket) self.logger.info(arpPacket)
if arpPacket.dst_mac == self.MAC_ADDR: if arpPacket.dst_mac in self.MAC_ADDR:
# learn mac 2 port mapping # learn mac 2 port mapping
self.mac_to_port[dpid][arpPacket.src_mac] = inPort self.mac_to_port[dpid][arpPacket.src_mac] = inPort
# learn ip 2 mac mapping # learn ip 2 mac mapping
@@ -166,12 +176,13 @@ class L3Switch(app_manager.RyuApp):
self.send_packet(datapath, outPort, p) self.send_packet(datapath, outPort, p)
def do_icmp(self, datapath, port, pkt_ethernet, pkt_ipv4, pkt_icmp): def do_icmp(self, datapath, port, pkt_ethernet, pkt_ipv4, pkt_icmp):
dpid = datapath.id
if pkt_icmp.type != icmp.ICMP_ECHO_REQUEST: if pkt_icmp.type != icmp.ICMP_ECHO_REQUEST:
return return
pkt = packet.Packet() pkt = packet.Packet()
pkt.add_protocol(ethernet.ethernet(ethertype=pkt_ethernet.ethertype, pkt.add_protocol(ethernet.ethernet(ethertype=pkt_ethernet.ethertype,
dst=pkt_ethernet.src, dst=pkt_ethernet.src,
src=self.MAC_ADDR)) src=dpid))
pkt.add_protocol(ipv4.ipv4(dst=pkt_ipv4.src, pkt.add_protocol(ipv4.ipv4(dst=pkt_ipv4.src,
src=pkt_ipv4.dst, src=pkt_ipv4.dst,
proto=pkt_ipv4.proto)) proto=pkt_ipv4.proto))
@@ -225,12 +236,12 @@ class L3Switch(app_manager.RyuApp):
# on the packet. # on the packet.
out_port = ofproto.OFPP_FLOOD out_port = ofproto.OFPP_FLOOD
dstMac = "FF:FF:FF:FF:FF:FF" 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. # Actions are applied in the same order as defined in the list.
# OFPActionOutput terminates the chain. So this call should be the last action. # OFPActionOutput terminates the chain. So this call should be the last action.
actions = [parser.OFPActionDecNwTtl(), #decrease TTL count 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.OFPActionSetField(eth_dst=dstMac), # set dst from arp request
parser.OFPActionOutput(out_port)] # forward packet through out_port 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 # 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) self.do_l2_switch(datapath, dpid, pkt, eth, in_port, msg.buffer_id)
return return
return return