simple_switch_13: using table-miss flow

OVS has not yet supported table-miss flow completely, but this patch
changes simple_switch_13 to install table-miss flow entry in accordance
with OF1.3 spec.

Signed-off-by: Yoshihiro Kaneko <ykaneko0929@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
Yoshihiro Kaneko 2013-10-16 14:36:49 +09:00 committed by FUJITA Tomonori
parent ab46901518
commit a94efcea3a

View File

@ -13,12 +13,9 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import logging
import struct
from ryu.base import app_manager from ryu.base import app_manager
from ryu.controller import ofp_event from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER from ryu.controller.handler import CONFIG_DISPATCHER, MAIN_DISPATCHER
from ryu.controller.handler import set_ev_cls from ryu.controller.handler import set_ev_cls
from ryu.ofproto import ofproto_v1_3 from ryu.ofproto import ofproto_v1_3
from ryu.lib.packet import packet from ryu.lib.packet import packet
@ -32,21 +29,33 @@ class SimpleSwitch13(app_manager.RyuApp):
super(SimpleSwitch13, self).__init__(*args, **kwargs) super(SimpleSwitch13, self).__init__(*args, **kwargs)
self.mac_to_port = {} self.mac_to_port = {}
def add_flow(self, datapath, port, dst, actions): @set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
def switch_features_handler(self, ev):
datapath = ev.msg.datapath
ofproto = datapath.ofproto ofproto = datapath.ofproto
parser = datapath.ofproto_parser
match = datapath.ofproto_parser.OFPMatch(in_port=port, # install table-miss flow entry
eth_dst=dst) #
inst = [datapath.ofproto_parser.OFPInstructionActions( # We specify NO BUFFER to max_len of the output action due to
ofproto.OFPIT_APPLY_ACTIONS, actions)] # 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.
match = parser.OFPMatch()
actions = [parser.OFPActionOutput(ofproto.OFPP_CONTROLLER,
ofproto.OFPCML_NO_BUFFER)]
self.add_flow(datapath, 0, match, actions)
mod = datapath.ofproto_parser.OFPFlowMod( def add_flow(self, datapath, priority, match, actions):
datapath=datapath, cookie=0, cookie_mask=0, table_id=0, ofproto = datapath.ofproto
command=ofproto.OFPFC_ADD, idle_timeout=0, hard_timeout=0, parser = datapath.ofproto_parser
priority=0, buffer_id=ofproto.OFP_NO_BUFFER,
out_port=ofproto.OFPP_ANY, inst = [parser.OFPInstructionActions(ofproto.OFPIT_APPLY_ACTIONS,
out_group=ofproto.OFPG_ANY, actions)]
flags=0, match=match, instructions=inst)
mod = parser.OFPFlowMod(datapath=datapath, priority=priority,
match=match, instructions=inst)
datapath.send_msg(mod) datapath.send_msg(mod)
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER) @set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
@ -54,6 +63,7 @@ class SimpleSwitch13(app_manager.RyuApp):
msg = ev.msg msg = ev.msg
datapath = msg.datapath datapath = msg.datapath
ofproto = datapath.ofproto ofproto = datapath.ofproto
parser = datapath.ofproto_parser
in_port = msg.match['in_port'] in_port = msg.match['in_port']
pkt = packet.Packet(msg.data) pkt = packet.Packet(msg.data)
@ -75,13 +85,17 @@ class SimpleSwitch13(app_manager.RyuApp):
else: else:
out_port = ofproto.OFPP_FLOOD out_port = ofproto.OFPP_FLOOD
actions = [datapath.ofproto_parser.OFPActionOutput(out_port)] actions = [parser.OFPActionOutput(out_port)]
# install a flow to avoid packet_in next time # install a flow to avoid packet_in next time
if out_port != ofproto.OFPP_FLOOD: if out_port != ofproto.OFPP_FLOOD:
self.add_flow(datapath, in_port, dst, actions) match = parser.OFPMatch(in_port=in_port, eth_dst=dst)
self.add_flow(datapath, 1, match, actions)
out = datapath.ofproto_parser.OFPPacketOut( data = None
datapath=datapath, buffer_id=msg.buffer_id, in_port=in_port, if msg.buffer_id == ofproto.OFP_NO_BUFFER:
actions=actions) 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) datapath.send_msg(out)