Hi, Deni
In your application, I think there is no one which calls "ovs_bridge()".
It is better to implement your code in Event Handlers.
For example, Features Reply Handler will be called when your application
gets the Features Reply message
(≒ when the connection to the OVS is established).
For details, you can read the Ryu Book and Ryu API Reference:
https://osrg.github.io/ryu-book/en/html/switching_hub.html#event-handler
http://ryu.readthedocs.io/en/latest/ryu_app_api.html#event-classes
And you have to specify the port with string, like this:
ovs_bridge.del_port('eth1')
Now I made a simple code by modifying simple_switch.py and attached it
to this mail.
Please check and try it! :)
Thanks,
Fujimoto
On 2017年04月25日 20:04, Deni Toruan wrote:
Dear Fujimoto san, thank you very much for your information.
I have tried to put the code to the file: simple_switch.py (as in
attachment), and try to run it in Ryu controller machine.
The code is running, how ever, when I checked in the OVS machine (VM
IP: 10.0.0.5), there is no changes. The port eth1 is still there.
Is there anything wrong in putting the code to file simple_switch.py?
thank you.
regards,
deni toruan
On Tue, Apr 25, 2017 at 1:40 AM, Fujimoto Satoshi
<satoshi.fujimo...@gmail.com <mailto:satoshi.fujimo...@gmail.com>> wrote:
Hi, Deni
You can make a connection by instantiating OVSBridge:
ovs_bridge = OVSBridge(None, datapath.id
<http://datapath.id>, 'tcp:127.0.0.1:6632
<http://127.0.0.1:6632>', timeout=1)
And by the following code, for example, you can delete a port:
ovs_bridge = OVSBridge(None, datapath.id
<http://datapath.id>, 'tcp:127.0.0.1:6632
<http://127.0.0.1:6632>', timeout=1)
ovs_bridge.init()
ports = ovs_bridge.get_port_name_list()
ovs_bridge.del_port(ports[0])
OVSBridge provides some other APIs.
For details, please check this code:
https://github.com/osrg/ryu/blob/master/ryu/lib/ovs/bridge.py
<https://github.com/osrg/ryu/blob/master/ryu/lib/ovs/bridge.py>
Thanks,
Fujimoto
On 2017年04月24日 16:18, Deni Toruan wrote:
Hi Satoshi san, thank you for your kind reply.
On Mon, Apr 24, 2017 at 5:07 AM, Fujimoto Satoshi
<satoshi.fujimo...@gmail.com
<mailto:satoshi.fujimo...@gmail.com>> wrote:
Hi, Deni
The problem may be caused by that you use "ovsdb_event" and
"ovs_vsctl" at the same time.
If you don't need to monitor the status of OVS, you should
not use "ovsdb_event".
Is it mean I should not use initiation :
"ovsdb_event.EventNewOVSDBConnection)"? So how I will make
(realize) a connection between controller and OVSDB Server?
Also, you can use "OVSBridge" to control your OVS.
"OVSBridge" calls "ovs_vsctl.VSCtl()" in __init__(), and
wraps some operations including adding a port.
Thank you for your suggestion.Would you mind to give me some clue
for using the "OVSBridge" and for calling the "ovs_vsctl.VSCtl()"?
Thanks,
Fujimoto
Thank you.
Regards, Deni
On 2017年04月23日 19:23, Deni Toruan wrote:
Dear all,
Currently, I am trying to make a connection between Ryu
Controller and OVS, and trying to modify OVS from controller
(add bridge, add port, delete port, etc) dynamically.
Currently, the OVS and Ryu controller can be connected. They
are running in different VM. However, when I try to run my
simple app, it didn't work. In the code, I am trying to
delete one port that I have already set up from OVS
terminal. I always got this in controller:
----------------------------
d5f55957-26e1-4e24-8b9c-bb15210aa220
New OVSDB connection from system id
d5f55957-26e1-4e24-8b9c-bb15210aa220
New connection from 10.0.0.11:47985 <http://10.0.0.11:47985>
instantiating app None of RemoteOvsdb
BRICK RemoteOvsdb-d5f55957-26e1-4e24-8b9c-bb15210aa220
EVENT OVSDB->SimpleSwitch EventNewOVSDBConnection
EventNewOVSDBConnection<system_id=d5f55957-26e1-4e24-8b9c-bb15210aa220>
d5f55957-26e1-4e24-8b9c-bb15210aa220
New OVSDB connection from system id
d5f55957-26e1-4e24-8b9c-bb15210aa220
instantiating app None of RemoteOvsdb
BRICK RemoteOvsdb-d5f55957-26e1-4e24-8b9c-bb15210aa220
EVENT OVSDB->SimpleSwitch EventNewOVSDBConnection
EventNewOVSDBConnection<system_id=d5f55957-26e1-4e24-8b9c-bb15210aa220>
d5f55957-26e1-4e24-8b9c-bb15210aa220
New OVSDB connection from system id
d5f55957-26e1-4e24-8b9c-bb15210aa220
New connection from 10.0.0.11:47986 <http://10.0.0.11:47986>
---------------------------------
For your information, I customize the code and I put it in
attachment. Please give some hints for doing this,
especially with the code. Thank you.
Best regards,
Deni Lumbantoruan
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org!http://sdm.link/slashdot
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
<mailto:Ryu-devel@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/ryu-devel
<https://lists.sourceforge.net/lists/listinfo/ryu-devel>
--
Deni Toruan
Dosen IT Del
Sitoluama
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org!http://sdm.link/slashdot
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
<mailto:Ryu-devel@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/ryu-devel
<https://lists.sourceforge.net/lists/listinfo/ryu-devel>
--
Deni Toruan
Dosen IT Del
Sitoluama
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel
# Copyright (C) 2011 Nippon Telegraph and Telephone Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
An OpenFlow 1.0 L2 learning switch implementation.
"""
from ryu.base import app_manager
from ryu.controller import ofp_event
from ryu.controller.handler import MAIN_DISPATCHER, CONFIG_DISPATCHER
from ryu.controller.handler import set_ev_cls
from ryu.ofproto import ofproto_v1_0
from ryu.lib.mac import haddr_to_bin
from ryu.lib.packet import packet
from ryu.lib.packet import ethernet
from ryu.lib.packet import ether_types
from ryu.lib.ovs.bridge import OVSBridge
class SimpleSwitch(app_manager.RyuApp):
OFP_VERSIONS = [ofproto_v1_0.OFP_VERSION]
def __init__(self, *args, **kwargs):
super(SimpleSwitch, 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
self.del_port('eth1', datapath)
def del_port(self, name, datapath):
ovs_bridge = OVSBridge(
None, datapath.id, 'tcp:10.0.0.5:6640', timeout=1)
ovs_bridge.init()
ovs_bridge.del_port(name)
def add_flow(self, datapath, in_port, dst, actions):
ofproto = datapath.ofproto
match = datapath.ofproto_parser.OFPMatch(
in_port=in_port, dl_dst=haddr_to_bin(dst))
mod = datapath.ofproto_parser.OFPFlowMod(
datapath=datapath, match=match, cookie=0,
command=ofproto.OFPFC_ADD, idle_timeout=0, hard_timeout=0,
priority=ofproto.OFP_DEFAULT_PRIORITY,
flags=ofproto.OFPFF_SEND_FLOW_REM, actions=actions)
datapath.send_msg(mod)
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
def _packet_in_handler(self, ev):
msg = ev.msg
datapath = msg.datapath
ofproto = datapath.ofproto
pkt = packet.Packet(msg.data)
eth = pkt.get_protocol(ethernet.ethernet)
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, msg.in_port)
# learn a mac address to avoid FLOOD next time.
self.mac_to_port[dpid][src] = msg.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 = [datapath.ofproto_parser.OFPActionOutput(out_port)]
# install a flow to avoid packet_in next time
if out_port != ofproto.OFPP_FLOOD:
self.add_flow(datapath, msg.in_port, dst, actions)
data = None
if msg.buffer_id == ofproto.OFP_NO_BUFFER:
data = msg.data
out = datapath.ofproto_parser.OFPPacketOut(
datapath=datapath, buffer_id=msg.buffer_id, in_port=msg.in_port,
actions=actions, data=data)
datapath.send_msg(out)
@set_ev_cls(ofp_event.EventOFPPortStatus, MAIN_DISPATCHER)
def _port_status_handler(self, ev):
msg = ev.msg
reason = msg.reason
port_no = msg.desc.port_no
ofproto = msg.datapath.ofproto
if reason == ofproto.OFPPR_ADD:
self.logger.info("port added %s", port_no)
elif reason == ofproto.OFPPR_DELETE:
self.logger.info("port deleted %s", port_no)
elif reason == ofproto.OFPPR_MODIFY:
self.logger.info("port modified %s", port_no)
else:
self.logger.info("Illeagal port state %s %s", port_no, reason)
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel