ofctl_rest: support Port Modification Message

this patch makes ofctl_rest enable use of Port Modification Message.

usage)

  URI:    /stats/portdesc/modify
  method: POST

the message body is as follows:

  dpid
  port_no    (default:0)
  config     (default:0)
  hw_addr    (default:automatic-setting)
  mask       (default:0)
  advertise  (default:automatic-setting)

e.g. )

  curl -X POST -d '{"dpid": 1,
                    "port_no": 1,
                    "mask": 0b0000001,
                    "config": 0b0000001}' http://localhost:8080/stats/portdesc/modify

Signed-off-by: TAKAHASHI Minoru <takahashi.minoru7@gmail.com>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
takahashi.minoru 2014-07-08 15:00:51 +09:00 committed by FUJITA Tomonori
parent 39c0fc00f9
commit 78786a47c6
4 changed files with 88 additions and 0 deletions

View File

@ -101,6 +101,9 @@ LOG = logging.getLogger('ryu.app.ofctl_rest')
# delete a group entry
# POST /stats/groupentry/delete
#
# modify behavior of the physical port
# POST /stats/portdesc/modify
#
#
# send a experimeter message
# POST /stats/experimenter/<dpid>
@ -380,6 +383,47 @@ class StatsController(ControllerBase):
return Response(status=200)
def mod_port_behavior(self, req, cmd, **_kwargs):
try:
port_config = eval(req.body)
except SyntaxError:
LOG.debug('invalid syntax %s', req.body)
return Response(status=400)
dpid = port_config.get('dpid')
port_no = int(port_config.get('port_no', 0))
port_info = self.dpset.port_state[int(dpid)].get(port_no)
if 'hw_addr' not in port_config:
if port_info is not None:
port_config['hw_addr'] = port_info.hw_addr
else:
return Response(status=404)
if 'advertise' not in port_config:
if port_info is not None:
port_config['advertise'] = port_info.advertised
else:
return Response(status=404)
dp = self.dpset.get(int(dpid))
if dp is None:
return Response(status=404)
if cmd != 'modify':
return Response(status=404)
if dp.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
ofctl_v1_0.mod_port_behavior(dp, port_config)
elif dp.ofproto.OFP_VERSION == ofproto_v1_2.OFP_VERSION:
ofctl_v1_2.mod_port_behavior(dp, port_config)
elif dp.ofproto.OFP_VERSION == ofproto_v1_3.OFP_VERSION:
ofctl_v1_3.mod_port_behavior(dp, port_config)
else:
LOG.debug('Unsupported OF protocol')
return Response(status=501)
def send_experimenter(self, req, dpid, **_kwargs):
dp = self.dpset.get(int(dpid))
if dp is None:
@ -493,6 +537,11 @@ class RestStatsApi(app_manager.RyuApp):
controller=StatsController, action='mod_group_entry',
conditions=dict(method=['POST']))
uri = path + '/portdesc/{cmd}'
mapper.connect('stats', uri,
controller=StatsController, action='mod_port_behavior',
conditions=dict(method=['POST']))
uri = path + '/experimenter/{dpid}'
mapper.connect('stats', uri,
controller=StatsController, action='send_experimenter',

View File

@ -308,3 +308,16 @@ def delete_flow_entry(dp):
command=dp.ofproto.OFPFC_DELETE)
dp.send_msg(flow_mod)
def mod_port_behavior(dp, port_config):
port_no = int(port_config.get('port_no', 0))
hw_addr = port_config.get('hw_addr')
config = int(port_config.get('config', 0))
mask = int(port_config.get('mask', 0))
advertise = int(port_config.get('advertise'))
port_mod = dp.ofproto_parser.OFPPortMod(
dp, port_no, hw_addr, config, mask, advertise)
dp.send_msg(port_mod)

View File

@ -822,6 +822,19 @@ def mod_group_entry(dp, group, cmd):
dp.send_msg(group_mod)
def mod_port_behavior(dp, port_config):
port_no = int(port_config.get('port_no', 0))
hw_addr = port_config.get('hw_addr')
config = int(port_config.get('config', 0))
mask = int(port_config.get('mask', 0))
advertise = int(port_config.get('advertise'))
port_mod = dp.ofproto_parser.OFPPortMod(
dp, port_no, hw_addr, config, mask, advertise)
dp.send_msg(port_mod)
def send_experimenter(dp, exp):
experimenter = exp.get('experimenter', 0)
exp_type = exp.get('exp_type', 0)

View File

@ -993,6 +993,19 @@ def mod_group_entry(dp, group, cmd):
dp.send_msg(group_mod)
def mod_port_behavior(dp, port_config):
port_no = int(port_config.get('port_no', 0))
hw_addr = port_config.get('hw_addr')
config = int(port_config.get('config', 0))
mask = int(port_config.get('mask', 0))
advertise = int(port_config.get('advertise'))
port_mod = dp.ofproto_parser.OFPPortMod(
dp, port_no, hw_addr, config, mask, advertise)
dp.send_msg(port_mod)
def send_experimenter(dp, exp):
experimenter = exp.get('experimenter', 0)
exp_type = exp.get('exp_type', 0)