I am trying to match the ip_dscp field using ryu controller i have made a small modification to the simple_switch_13.py app in ryu. it worked fine when i tried in mininet with openflow13 switch but it wont match ip_dscp when i used Hp aruba 3810m switch. i have included the ryu app and flow tables for hp and openflow13 switch below.
Thanks
here is the modified simple_switch_13.py app i am using:
class SimpleSwitch13(app_manager.RyuApp):
OFP_VERSIONS = [ofproto_v1_3.OFP_VERSION]
def __init__(self, *args, **kwargs):
super(SimpleSwitch13, self).__init__(*args, **kwargs)
self.mac_to_port = {}
@SET_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
def switch_features_handler(self, ev):
datapath = ev.msg.datapath
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
# install table-miss flow entry
#
# We specify NO BUFFER to max_len of the output action due to
# OVS bug. At this moment, if we specify a lesser number, e.g.,
# 128, OVS will send Packet-In with invalid buffer_id and
# truncated packet data. In that case, we cannot output packets
# correctly. The bug has been fixed in OVS v2.1.0.
match = parser.OFPMatch()
actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,
ofproto.OFPCML_NO_BUFFER)]
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
inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
actions)]
if buffer_id:
mod = parser.OFPFlowMod(datapath=datapath, table_id=200, buffer_id=buffer_id,
priority=priority, match=match,
instructions=inst)
else:
mod = parser.OFPFlowMod(datapath=datapath, table_id=200, priority=priority,
match=match, instructions=inst)
datapath.send_msg(mod)
@SET_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
def _packet_in_handler(self, ev):
# If you hit this you might want to increase
# the "miss_send_length" of your switch
if ev.msg.msg_len < ev.msg.total_len:
self.logger.debug("packet truncated: only %s of %s bytes",
ev.msg.msg_len, ev.msg.total_len)
msg = ev.msg
datapath = msg.datapath
ofproto = datapath.ofproto
parser = datapath.ofproto_parser
in_port = msg.match['in_port']
ip_dscp = msg.match.get('ip_dscp')
#print 'ip dscp',ip_dscp
pkt = packet.Packet(msg.data)
eth = pkt.get_protocols(ethernet.ethernet)[0]
pkt = packet.Packet(msg.data)
arp_pkt = pkt.get_protocol(arp.arp)
ip_pkt = pkt.get_protocol(ipv4.ipv4)
if eth.ethertype == ether_types.ETH_TYPE_LLDP:
# ignore lldp packet
return
dst = eth.dst
src=eth.src
dpid = datapath.id
self.mac_to_port.setdefault(dpid, {})
self.logger.info("packet in %s %s %s %s", dpid, src, dst, in_port)
# learn a mac address to avoid FLOOD next time.
self.mac_to_port[dpid][src] = in_port
if dst in self.mac_to_port[dpid]:
out_port = self.mac_to_port[dpid][dst]
else:
out_port = ofproto.OFPP_FLOOD
actions = [parser.OFPActionOutput(out_port)]
arp_pkt = pkt.get_protocol(arp.arp)
# install a flow to avoid packet_in next time
if out_port != ofproto.OFPP_FLOOD:
if arp_pkt:
match = parser.OFPMatch( in_port=in_port, eth_src=src)
elif ip_dscp is not None and ip_dscp != 0:
match = parser.OFPMatch( eth_type=0x0800,ipv4_src=ip_pkt.src, ipv4_dst=ip_pkt.dst, ip_dscp=ip_dscp)
else:
match = parser.OFPMatch( eth_type=0x0800, ipv4_src=ip_pkt.src, ipv4_dst=ip_pkt.dst)
# verify if we have a valid buffer_id, if yes avoid to send both
# flow_mod & packet_out
if msg.buffer_id != ofproto.OFP_NO_BUFFER:
self.add_flow(datapath, 1, match, actions, msg.buffer_id)
return
else:
self.add_flow(datapath, 1, match, actions)
data = None
if msg.buffer_id == ofproto.OFP_NO_BUFFER:
data = msg.data
out = parser.OFPPacketOut(datapath=datapath, buffer_id=msg.buffer_id,
in_port=in_port, actions=actions, data=data)
datapath.send_msg(out)
This is the flow table when i used in mininet: you can see its matching difference ip_dscp values
RECEIVED (xid=0xF0FF00F0):
stat_repl{type="flow", flags="0x0", stats=[{table="0", match="oxm{in_port="2", eth_src="9e:3e:57:3c:5c:6a", eth_type="0x806"}", dur_s="129", dur_ns="342000000", prio="1", idle_to="0", hard_to="0", cookie="0x0", pkt_cnt="5", byte_cnt="300", insts=[apply{acts=[out{port="1"}]}]},
{table="0", match="oxm{eth_type="0x800", ip_dscp="42", ipv4_src="10.0.0.1", ipv4_dst="10.0.0.2"}", dur_s="129", dur_ns="339000000", prio="1", idle_to="0", hard_to="0", cookie="0x0", pkt_cnt="74", byte_cnt="7252", insts=[apply{acts=[out{port="2"}]}]},
{table="0", match="oxm{eth_type="0x800", ip_dscp="42", ipv4_src="10.0.0.2", ipv4_dst="10.0.0.1"}", dur_s="129", dur_ns="329000000", prio="1", idle_to="0", hard_to="0", cookie="0x0", pkt_cnt="74", byte_cnt="7252", insts=[apply{acts=[out{port="1"}]}]},
{table="0", match="oxm{in_port="1", eth_src="42:7f:56:b5:4c:10", eth_type="0x806"}", dur_s="124", dur_ns="317000000", prio="1", idle_to="0", hard_to="0", cookie="0x0", pkt_cnt="4", byte_cnt="240", insts=[apply{acts=[out{port="2"}]}]},
{table="0", match="oxm{eth_type="0x800", ip_dscp="40", ipv4_src="10.0.0.1", ipv4_dst="10.0.0.2"}", dur_s="48", dur_ns="895000000", prio="1", idle_to="0", hard_to="0", cookie="0x0", pkt_cnt="42", byte_cnt="4116", insts=[apply{acts=[out{port="2"}]}]},
{table="0", match="oxm{eth_type="0x800", ip_dscp="40", ipv4_src="10.0.0.2", ipv4_dst="10.0.0.1"}", dur_s="48", dur_ns="883000000", prio="1", idle_to="0", hard_to="0", cookie="0x0", pkt_cnt="42", byte_cnt="4116", insts=[apply{acts=[out{port="1"}]}]},
{table="0", match="oxm{eth_type="0x800", ip_dscp="10", ipv4_src="10.0.0.1", ipv4_dst="10.0.0.2"}", dur_s="2", dur_ns="475000000", prio="1", idle_to="0", hard_to="0", cookie="0x0", pkt_cnt="3", byte_cnt="294", insts=[apply{acts=[out{port="2"}]}]},
{table="0", match="oxm{eth_type="0x800", ip_dscp="10", ipv4_src="10.0.0.2", ipv4_dst="10.0.0.1"}", dur_s="2", dur_ns="465000000", prio="1", idle_to="0", hard_to="0", cookie="0x0", pkt_cnt="3", byte_cnt="294", insts=[apply{acts=[out{port="1"}]}]},
{table="0", match="oxm{all match}", dur_s="164", dur_ns="472000000", prio="0", idle_to="0", hard_to="0", cookie="0x0", pkt_cnt="25", byte_cnt="2480", insts=[apply{acts=[out{port="ctrl", mlen="65535"}]}]}]}
This is the flow table when i use hp switch it does not match the ip_dscp field
Flow 1
Match
Incoming Port : Any Ethernet Type : Any
Source MAC : Any Destination MAC : Any
Source MAC Mask : 000000-000000
Destination MAC Mask : 000000-000000
VLAN ID : Any VLAN Priority : Any
Source IP Address : Any
Destination IP Address : Any
IP Protocol : Any
IP ECN : Any IP DSCP : Any
Source Port : Any Destination Port : Any
Source Port Range : NA
Destination Port Range : NA
TCP Flags : NA
Custom Match One : Any
Custom Match One Mask : Any
Custom Match Two : Any
Custom Match Two Mask : Any
Custom Match Three : Any
Custom Match Three Mask : Any
Custom Match Four : Any
Custom Match Four Mask : Any
Attributes
Priority : 0 Duration : 3396 seconds
Hard Timeout : 0 seconds Idle Timeout : 0 seconds
Byte Count : NA Packet Count : NA
Flow Table ID : 0 Controller ID : NA
Cookie : 0x0
Hardware Index: NA
Instructions
Goto Table ID : 100
Flow 2
Match
Incoming Port : 3 Ethernet Type : ARP
Source MAC : 001cc0-6cf6dc Destination MAC : Any
Source MAC Mask : ffffff-ffffff
Destination MAC Mask : 000000-000000
VLAN ID : Any VLAN Priority : Any
Source Protocol Address : Any
Target Protocol Address : Any
Source Hardware Address : Any
Source Hardware Address Mask : 000000-000000
Target Hardware Address : Any
Target Hardware Address Mask : 000000-000000
ARP Opcode : Any
IP ECN : Any IP DSCP : Any
Source Port : Any Destination Port : Any
Source Port Range : NA
Destination Port Range : NA
TCP Flags : NA
TCP Mask : NA
Custom Match One : Any
Custom Match One Mask : Any
Custom Match Two : Any
Custom Match Two Mask : Any
Custom Match Three : Any
Custom Match Three Mask : Any
Custom Match Four : Any
Custom Match Four Mask : Any
Attributes
Priority : 1 Duration : 59 seconds
Hard Timeout : 0 seconds Idle Timeout : 0 seconds
Byte Count : NA Packet Count : 2
Flow Table ID : 100 Controller ID : 1
Cookie : 0x0
Hardware Index: 0
Instructions
Apply Actions
Output : 4
Flow 3
Match
Incoming Port : 4 Ethernet Type : ARP
Source MAC : 001676-a0a1a8 Destination MAC : Any
Source MAC Mask : ffffff-ffffff
Destination MAC Mask : 000000-000000
VLAN ID : Any VLAN Priority : Any
Source Protocol Address : Any
Target Protocol Address : Any
Source Hardware Address : Any
Source Hardware Address Mask : 000000-000000
Target Hardware Address : Any
Target Hardware Address Mask : 000000-000000
ARP Opcode : Any
IP ECN : Any IP DSCP : Any
Source Port : Any Destination Port : Any
Source Port Range : NA
Destination Port Range : NA
TCP Flags : NA
TCP Mask : NA
Custom Match One : Any
Custom Match One Mask : Any
Custom Match Two : Any
Custom Match Two Mask : Any
Custom Match Three : Any
Custom Match Three Mask : Any
Custom Match Four : Any
Custom Match Four Mask : Any
Attributes
Priority : 1 Duration : 64 seconds
Hard Timeout : 0 seconds Idle Timeout : 0 seconds
Byte Count : NA Packet Count : 3
Flow Table ID : 100 Controller ID : 1
Cookie : 0x0
Hardware Index: 0
Instructions
Apply Actions
Output : 3
Flow 4
Match
Incoming Port : Any Ethernet Type : IP
Source MAC : Any Destination MAC : Any
Source MAC Mask : 000000-000000
Destination MAC Mask : 000000-000000
VLAN ID : Any VLAN Priority : Any
Source IP Address : 10.0.0.1/255.255.255.255
Destination IP Address : 10.0.0.2/255.255.255.255
IP Protocol : Any
IP ECN : Any IP DSCP : Any
Source Port : Any Destination Port : Any
Source Port Range : NA
Destination Port Range : NA
TCP Flags : NA
TCP Mask : NA
Custom Match One : Any
Custom Match One Mask : Any
Custom Match Two : Any
Custom Match Two Mask : Any
Custom Match Three : Any
Custom Match Three Mask : Any
Custom Match Four : Any
Custom Match Four Mask : Any
Attributes
Priority : 1 Duration : 64 seconds
Hard Timeout : 0 seconds Idle Timeout : 0 seconds
Byte Count : NA Packet Count : 56
Flow Table ID : 100 Controller ID : 1
Cookie : 0x0
Hardware Index: 0
Instructions
Apply Actions
Output : 4
Flow 5
Match
Incoming Port : Any Ethernet Type : IP
Source MAC : Any Destination MAC : Any
Source MAC Mask : 000000-000000
Destination MAC Mask : 000000-000000
VLAN ID : Any VLAN Priority : Any
Source IP Address : 10.0.0.2/255.255.255.255
Destination IP Address : 10.0.0.1/255.255.255.255
IP Protocol : Any
IP ECN : Any IP DSCP : Any
Source Port : Any Destination Port : Any
Source Port Range : NA
Destination Port Range : NA
TCP Flags : NA
TCP Mask : NA
Custom Match One : Any
Custom Match One Mask : Any
Custom Match Two : Any
Custom Match Two Mask : Any
Custom Match Three : Any
Custom Match Three Mask : Any
Custom Match Four : Any
Custom Match Four Mask : Any
Attributes
Priority : 1 Duration : 64 seconds
Hard Timeout : 0 seconds Idle Timeout : 0 seconds
Byte Count : NA Packet Count : 56
Flow Table ID : 100 Controller ID : 1
Cookie : 0x0
Hardware Index: 0
Instructions
Apply Actions
Output : 3
Flow 6
Match
Incoming Port : Any Ethernet Type : Any
Source MAC : Any Destination MAC : Any
Source MAC Mask : 000000-000000
Destination MAC Mask : 000000-000000
VLAN ID : Any VLAN Priority : Any
Source IP Address : Any
Destination IP Address : Any
IP Protocol : Any
IP ECN : Any IP DSCP : Any
Source Port : Any Destination Port : Any
Source Port Range : NA
Destination Port Range : NA
TCP Flags : NA
TCP Mask : NA
Custom Match One : Any
Custom Match One Mask : Any
Custom Match Two : Any
Custom Match Two Mask : Any
Custom Match Three : Any
Custom Match Three Mask : Any
Custom Match Four : Any
Custom Match Four Mask : Any
Attributes
Priority : 0 Duration : 65 seconds
Hard Timeout : 0 seconds Idle Timeout : 0 seconds
Byte Count : NA Packet Count : 4329
Flow Table ID : 100 Controller ID : 1
Cookie : 0x0
Hardware Index: NA
Instructions
Apply Actions
Controller Port
Flow 7
Match
Incoming Port : Any Ethernet Type : Any
Source MAC : Any Destination MAC : Any
Source MAC Mask : 000000-000000
Destination MAC Mask : 000000-000000
VLAN ID : Any VLAN Priority : Any
Source IP Address : Any
Destination IP Address : Any
IP Protocol : Any
IP ECN : Any IP DSCP : Any
Source Port : Any Destination Port : Any
Source Port Range : NA
Destination Port Range : NA
TCP Flags : NA
TCP Mask : NA
Custom Match One : Any
Custom Match One Mask : Any
Custom Match Two : Any
Custom Match Two Mask : Any
Custom Match Three : Any
Custom Match Three Mask : Any
Custom Match Four : Any
Custom Match Four Mask : Any
Attributes
Priority : 0 Duration : 3396 seconds
Hard Timeout : 0 seconds Idle Timeout : 0 seconds
Byte Count : 0 Packet Count : 0
Flow Table ID : 200 Controller ID : 1
Cookie : 0x0
Hardware Index: NA
Instructions
Apply Actions
Controller Port