Update and rename MantenerFIFO to MantenerFIFO.md
[vsorcdistro/.git] / ryu / doc / source / library_ovsdb_manager.rst
1 *********************
2 OVSDB Manager library
3 *********************
4
5 Path: ``ryu.services.protocols.ovsdb``
6
7 Introduction
8 ============
9
10 Ryu OVSDB Manager library allows your code to interact with devices
11 speaking the OVSDB protocol. This enables your code to perform remote
12 management of the devices and react to topology changes on them.
13
14 Please note this library will spawn a server listening on the port 6640 (the
15 IANA registered for OVSDB protocol), but does not initiate connections from
16 controller side.
17 Then, to make your devices connect to Ryu, you need to tell the controller IP
18 address and port to your devices.
19
20 .. code-block:: bash
21
22     # Show current configuration
23     $ ovs-vsctl get-manager
24
25     # Set manager (controller) address
26     $ ovs-vsctl set-manager "tcp:127.0.0.1:6640"
27
28     # If you want to specify IPv6 address, wrap ip with brackets
29     $ ovs-vsctl set-manager "tcp:[::1]:6640"
30
31 Also this library identifies the devices by "system-id" which should be unique,
32 persistent identifier among all devices connecting to a single controller.
33 Please make sure "system-id" is configured before connecting.
34
35 .. code-block:: bash
36
37     # Show current configuration
38     $ ovs-vsctl get Open_vSwitch . external_ids:system-id
39
40     # Set system-id manually
41     $ ovs-vsctl set Open_vSwitch . external_ids:system-id=<SYSTEM-ID>
42
43 Example
44 =======
45
46 The following logs all new OVSDB connections in "handle_new_ovsdb_connection"
47 and also provides the API "create_port" for creating a port on a bridge.
48
49 .. code-block:: python
50
51     import uuid
52
53     from ryu.base import app_manager
54     from ryu.controller.handler import set_ev_cls
55     from ryu.services.protocols.ovsdb import api as ovsdb
56     from ryu.services.protocols.ovsdb import event as ovsdb_event
57
58
59     class MyApp(app_manager.RyuApp):
60         @set_ev_cls(ovsdb_event.EventNewOVSDBConnection)
61         def handle_new_ovsdb_connection(self, ev):
62             system_id = ev.system_id
63             address = ev.client.address
64             self.logger.info(
65                 'New OVSDB connection from system-id=%s, address=%s',
66                 system_id, address)
67
68             # Example: If device has bridge "s1", add port "s1-eth99"
69             if ovsdb.bridge_exists(self, system_id, "s1"):
70                 self.create_port(system_id, "s1", "s1-eth99")
71
72         def create_port(self, system_id, bridge_name, name):
73             new_iface_uuid = uuid.uuid4()
74             new_port_uuid = uuid.uuid4()
75
76             bridge = ovsdb.row_by_name(self, system_id, bridge_name)
77
78             def _create_port(tables, insert):
79                 iface = insert(tables['Interface'], new_iface_uuid)
80                 iface.name = name
81                 iface.type = 'internal'
82
83                 port = insert(tables['Port'], new_port_uuid)
84                 port.name = name
85                 port.interfaces = [iface]
86
87                 bridge.ports = bridge.ports + [port]
88
89                 return new_port_uuid, new_iface_uuid
90
91             req = ovsdb_event.EventModifyRequest(system_id, _create_port)
92             rep = self.send_request(req)
93
94             if rep.status != 'success':
95                 self.logger.error('Error creating port %s on bridge %s: %s',
96                                   name, bridge, rep.status)
97                 return None
98
99             return rep.insert_uuids[new_port_uuid]