Sha256: fb77afb183f3a86787ebf2f57727c3d0432d8f349db4e6cd40facb6b72ca6ae3
Contents?: true
Size: 1.96 KB
Versions: 16
Compression:
Stored size: 1.96 KB
Contents
# # Simple learning switch application in Ruby # # Copyright (C) 2008-2013 NEC Corporation # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # require "fdb" # # A OpenFlow controller class that emulates a layer-2 switch. # class LearningSwitch < Controller add_timer_event :age_fdb, 5, :periodic def start @fdb = FDB.new end def packet_in datapath_id, message @fdb.learn message.macsa, message.in_port port_no = @fdb.port_no_of( message.macda ) if port_no flow_mod datapath_id, message, port_no packet_out datapath_id, message, port_no else flood datapath_id, message end end def age_fdb @fdb.age end ############################################################################## private ############################################################################## def flow_mod datapath_id, message, port_no send_flow_mod_add( datapath_id, :match => ExactMatch.from( message ), :actions => ActionOutput.new( :port => port_no ) ) end def packet_out datapath_id, message, port_no send_packet_out( datapath_id, :packet_in => message, :actions => ActionOutput.new( :port => port_no ) ) end def flood datapath_id, message packet_out datapath_id, message, OFPP_FLOOD end end ### Local variables: ### mode: Ruby ### coding: utf-8 ### indent-tabs-mode: nil ### End:
Version data entries
16 entries across 16 versions & 1 rubygems