Skip to content

Commit

Permalink
ovs: Add API corresponding to ovs-vsctl add-bond command
Browse files Browse the repository at this point in the history
Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
  • Loading branch information
iwaseyusuke authored and fujita committed Oct 25, 2016
1 parent fe83cfd commit d19e7a3
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
22 changes: 22 additions & 0 deletions ryu/lib/ovs/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,28 @@ def get_port_name_list(self):
self.run_command([command])
return command.result

def add_bond(self, name, ifaces, bond_mode=None, lacp=None):
"""
Creates a bonded port.
:param name: Port name to be created
:param ifaces: List of interfaces containing at least 2 interfaces
:param bond_mode: Bonding mode (active-backup, balance-tcp
or balance-slb)
:param lacp: LACP mode (active, passive or off)
"""
assert len(ifaces) >= 2

options = ''
if bond_mode:
options += 'bond_mode=%(bond_mode)s' % locals()
if lacp:
options += 'lacp=%(lacp)s' % locals()

command_add = ovs_vsctl.VSCtlCommand(
'add-bond', (self.br_name, name, ifaces), options)
self.run_command([command_add])

def add_tunnel_port(self, name, tunnel_type, remote_ip,
local_ip=None, key=None, ofport=None):
options = 'remote_ip=%(remote_ip)s' % locals()
Expand Down
28 changes: 27 additions & 1 deletion ryu/lib/ovs/vsctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ def _run_command(self, commands):
# Port. commands
'list-ports': (self._pre_get_info, self._cmd_list_ports),
'add-port': (self._pre_cmd_add_port, self._cmd_add_port),
# 'add-bond':
'add-bond': (self._pre_cmd_add_bond, self._cmd_add_bond),
'del-port': (self._pre_get_info, self._cmd_del_port),
# 'port-to-br':

Expand Down Expand Up @@ -1338,6 +1338,18 @@ def _pre_cmd_add_port(self, ctx, command):

self._pre_add_port(ctx, columns)

def _pre_cmd_add_bond(self, ctx, command):
self._pre_get_info(ctx, command)

if len(command.args) < 3:
vsctl_fatal('this command requires at least 3 arguments')

columns = [
ctx.parse_column_key_value(
self.schema.tables[vswitch_idl.OVSREC_TABLE_PORT],
setting)[0] for setting in command.args[3:]]
self._pre_add_port(ctx, columns)

def _cmd_add_port(self, ctx, command):
may_exist = command.has_option('--may_exist')

Expand All @@ -1352,6 +1364,20 @@ def _cmd_add_port(self, ctx, command):
ctx.add_port(br_name, port_name, may_exist,
False, iface_names, settings)

def _cmd_add_bond(self, ctx, command):
may_exist = command.has_option('--may_exist')
fake_iface = command.has_option('--fake-iface')

br_name = command.args[0]
port_name = command.args[1]
iface_names = list(command.args[2])
settings = [
ctx.parse_column_key_value(
self.schema.tables[vswitch_idl.OVSREC_TABLE_PORT],
setting) for setting in command.args[3:]]
ctx.add_port(br_name, port_name, may_exist, fake_iface,
iface_names, settings)

def _del_port(self, ctx, br_name=None, target=None,
must_exist=False, with_iface=False):
assert target is not None
Expand Down

0 comments on commit d19e7a3

Please sign in to comment.