ofctl_v1_2/3: fix match conditions about ARP

ofctl_v1_0 has changed nw_src/dst into ipv4_src/dst or arp_spa/tpa automatically like ovs-ofctl.
since ofctl_v1_2/3 change nw_src/dst only into ipv4_src/dst, it cannot create the match conditions which use arp_spa/tpa.
this patch fixes this problem.

before applying this patch (using ofctl_rest):

  curl -X POST -d '{"dpid": 1,
                    "match": {"dl_type": 2048,
                              "nw_src": "192.168.0.0/24"},
                    "actions": [{"type": "OUTPUT",
                                 "port": 2}]}' http://localhost:8080/stats/flowentry/add

  OFPST_FLOW reply (OF1.3) (xid=0x2):
   cookie=0x0, duration=3.602s, table=0, n_packets=0, n_bytes=0, priority=0,ip,nw_src=192.168.0.0/24 actions=output:2

  curl -X POST -d '{"dpid": 1,
                    "match": {"dl_type": 2054,
                              "nw_src": "192.168.0.0/24"},
                    "actions": [{"type": "OUTPUT",
                                 "port": 2}]}' http://localhost:8080/stats/flowentry/add

  no flow entry was installed.

after applying this patch (using ofctl_rest):

  curl -X POST -d '{"dpid": 1,
                    "match": {"dl_type": 2048,
                              "nw_src": "192.168.0.0/24"},
                    "actions": [{"type": "OUTPUT",
                                 "port": 2}]}' http://localhost:8080/stats/flowentry/add

  OFPST_FLOW reply (OF1.3) (xid=0x2):
   cookie=0x0, duration=3.602s, table=0, n_packets=0, n_bytes=0, priority=0,ip,nw_src=192.168.0.0/24 actions=output:2

  curl -X POST -d '{"dpid": 1,
                    "match": {"dl_type": 2054,
                              "nw_src": "192.168.0.0/24"},
                    "actions": [{"type": "OUTPUT",
                                 "port": 2}]}' http://localhost:8080/stats/flowentry/add

  OFPST_FLOW reply (OF1.3) (xid=0x2):
   cookie=0x0, duration=2.555s, table=0, n_packets=0, n_bytes=0, priority=0,arp,arp_spa=192.168.0.0/24 actions=output:2

Signed-off-by: Yuichi Ito <ito.yuichi0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Yuichi Ito 2014-01-14 13:58:20 +09:00 committed by FUJITA Tomonori
parent 328385df86
commit faebcd2b3f
2 changed files with 30 additions and 0 deletions

View File

@ -19,6 +19,7 @@ import socket
import logging
import netaddr
from ryu.ofproto import ether
from ryu.ofproto import inet
from ryu.ofproto import ofproto_v1_2
from ryu.ofproto import ofproto_v1_2_parser
@ -228,6 +229,8 @@ def to_match(dp, attrs):
'tcp_dst': int,
'udp_src': int,
'udp_dst': int,
'arp_spa': to_match_ip,
'arp_tpa': to_match_ip,
'ipv6_src': to_match_ipv6,
'ipv6_dst': to_match_ipv6}
@ -252,15 +255,27 @@ def to_match(dp, attrs):
'tcp_dst': to_match_tpdst,
'udp_src': to_match_tpsrc,
'udp_dst': to_match_tpdst,
'arp_spa': match.set_arp_spa_masked,
'arp_tpa': match.set_arp_tpa_masked,
'ipv6_src': match.set_ipv6_src_masked,
'ipv6_dst': match.set_ipv6_dst_masked}
if attrs.get('dl_type') == ether.ETH_TYPE_ARP or \
attrs.get('eth_type') == ether.ETH_TYPE_ARP:
if 'nw_src' in attrs and not 'arp_spa' in attrs:
attrs['arp_spa'] = attrs['nw_src']
del attrs['nw_src']
if 'nw_dst' in attrs and not 'arp_tpa' in attrs:
attrs['arp_tpa'] = attrs['nw_dst']
del attrs['nw_dst']
for key, value in attrs.items():
if key in convert:
value = convert[key](value)
if key in match_append:
if key == 'nw_src' or key == 'nw_dst' or \
key == 'ipv4_src' or key == 'ipv4_dst' or \
key == 'arp_spa' or key == 'arp_tpa' or \
key == 'ipv6_src' or key == 'ipv6_dst':
# IP address
ip = value[0]

View File

@ -19,6 +19,7 @@ import socket
import logging
import netaddr
from ryu.ofproto import ether
from ryu.ofproto import inet
from ryu.ofproto import ofproto_v1_3
from ryu.ofproto import ofproto_v1_3_parser
@ -247,6 +248,8 @@ def to_match(dp, attrs):
'tcp_dst': int,
'udp_src': int,
'udp_dst': int,
'arp_spa': to_match_ip,
'arp_tpa': to_match_ip,
'ipv6_src': to_match_ipv6,
'ipv6_dst': to_match_ipv6}
@ -273,15 +276,27 @@ def to_match(dp, attrs):
'tcp_dst': to_match_tpdst,
'udp_src': to_match_tpsrc,
'udp_dst': to_match_tpdst,
'arp_spa': match.set_arp_spa_masked,
'arp_tpa': match.set_arp_tpa_masked,
'ipv6_src': match.set_ipv6_src_masked,
'ipv6_dst': match.set_ipv6_dst_masked}
if attrs.get('dl_type') == ether.ETH_TYPE_ARP or \
attrs.get('eth_type') == ether.ETH_TYPE_ARP:
if 'nw_src' in attrs and not 'arp_spa' in attrs:
attrs['arp_spa'] = attrs['nw_src']
del attrs['nw_src']
if 'nw_dst' in attrs and not 'arp_tpa' in attrs:
attrs['arp_tpa'] = attrs['nw_dst']
del attrs['nw_dst']
for key, value in attrs.items():
if key in convert:
value = convert[key](value)
if key in match_append:
if key == 'nw_src' or key == 'nw_dst' or \
key == 'ipv4_src' or key == 'ipv4_dst' or \
key == 'arp_spa' or key == 'arp_tpa' or \
key == 'ipv6_src' or key == 'ipv6_dst':
# IP address
ip = value[0]