log-cleanup: per RyuApp logger
let RyuApp provide its own logger. use it instead of per-module logger where appropriate. Signed-off-by: YAMAMOTO Takashi <yamamoto@valinux.co.jp> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
acc692a6f0
commit
998a8ad543
@ -32,9 +32,6 @@ from ryu.lib import dpid as dpid_lib
|
|||||||
from ryu.lib import mac
|
from ryu.lib import mac
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def _is_reserved_port(ofproto, port_no):
|
def _is_reserved_port(ofproto, port_no):
|
||||||
return port_no > ofproto.OFPP_MAX
|
return port_no > ofproto.OFPP_MAX
|
||||||
|
|
||||||
@ -249,7 +246,7 @@ class PortSet(app_manager.RyuApp):
|
|||||||
if not enter_leave:
|
if not enter_leave:
|
||||||
# TODO:XXX
|
# TODO:XXX
|
||||||
# What to do on datapath disconnection?
|
# What to do on datapath disconnection?
|
||||||
LOG.debug('dp disconnection ev:%s', ev)
|
self.logger.debug('dp disconnection ev:%s', ev)
|
||||||
|
|
||||||
dpid = ev.dp.id
|
dpid = ev.dp.id
|
||||||
ports = set(port.port_no for port in ev.ports)
|
ports = set(port.port_no for port in ev.ports)
|
||||||
@ -928,7 +925,7 @@ class GRETunnel(app_manager.RyuApp):
|
|||||||
# follows vm port deletion.
|
# follows vm port deletion.
|
||||||
# the tunnel port is deleted if and only if no instance of same
|
# the tunnel port is deleted if and only if no instance of same
|
||||||
# tenants resides in both nodes of tunnel end points.
|
# tenants resides in both nodes of tunnel end points.
|
||||||
LOG.debug('tunnel_port_del %s', ev)
|
self.logger.debug('tunnel_port_del %s', ev)
|
||||||
dp = self.dpset.get(ev.dpid)
|
dp = self.dpset.get(ev.dpid)
|
||||||
|
|
||||||
# SRC_TABLE: TUNNEL-port catch-all drop rule
|
# SRC_TABLE: TUNNEL-port catch-all drop rule
|
||||||
@ -939,11 +936,11 @@ class GRETunnel(app_manager.RyuApp):
|
|||||||
|
|
||||||
@handler.set_ev_handler(PortSet.EventTunnelKeyDel)
|
@handler.set_ev_handler(PortSet.EventTunnelKeyDel)
|
||||||
def tunnel_key_del_handler(self, ev):
|
def tunnel_key_del_handler(self, ev):
|
||||||
LOG.debug('tunnel_key_del ev %s', ev)
|
self.logger.debug('tunnel_key_del ev %s', ev)
|
||||||
|
|
||||||
@handler.set_ev_handler(PortSet.EventVMPort)
|
@handler.set_ev_handler(PortSet.EventVMPort)
|
||||||
def vm_port_handler(self, ev):
|
def vm_port_handler(self, ev):
|
||||||
LOG.debug('vm_port ev %s', ev)
|
self.logger.debug('vm_port ev %s', ev)
|
||||||
if ev.add_del:
|
if ev.add_del:
|
||||||
self._vm_port_add(ev)
|
self._vm_port_add(ev)
|
||||||
else:
|
else:
|
||||||
@ -951,7 +948,7 @@ class GRETunnel(app_manager.RyuApp):
|
|||||||
|
|
||||||
@handler.set_ev_handler(PortSet.EventTunnelPort)
|
@handler.set_ev_handler(PortSet.EventTunnelPort)
|
||||||
def tunnel_port_handler(self, ev):
|
def tunnel_port_handler(self, ev):
|
||||||
LOG.debug('tunnel_port ev %s', ev)
|
self.logger.debug('tunnel_port ev %s', ev)
|
||||||
if ev.add_del:
|
if ev.add_del:
|
||||||
self._tunnel_port_add(ev)
|
self._tunnel_port_add(ev)
|
||||||
else:
|
else:
|
||||||
@ -961,6 +958,6 @@ class GRETunnel(app_manager.RyuApp):
|
|||||||
def packet_in_handler(self, ev):
|
def packet_in_handler(self, ev):
|
||||||
# for debug
|
# for debug
|
||||||
msg = ev.msg
|
msg = ev.msg
|
||||||
LOG.debug('packet in ev %s msg %s', ev, ev.msg)
|
self.logger.debug('packet in ev %s msg %s', ev, ev.msg)
|
||||||
if msg.buffer_id != 0xffffffff: # TODO:XXX use constant instead of -1
|
if msg.buffer_id != 0xffffffff: # TODO:XXX use constant instead of -1
|
||||||
msg.datapath.send_packet_out(msg.buffer_id, msg.in_port, [])
|
msg.datapath.send_packet_out(msg.buffer_id, msg.in_port, [])
|
||||||
|
@ -40,11 +40,10 @@ from gevent import monkey
|
|||||||
monkey.patch_all()
|
monkey.patch_all()
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
|
||||||
|
|
||||||
def _get_auth_token():
|
def _get_auth_token(logger):
|
||||||
httpclient = q_client.HTTPClient(
|
httpclient = q_client.HTTPClient(
|
||||||
username=CONF.quantum_admin_username,
|
username=CONF.quantum_admin_username,
|
||||||
tenant_name=CONF.quantum_admin_tenant_name,
|
tenant_name=CONF.quantum_admin_tenant_name,
|
||||||
@ -55,9 +54,9 @@ def _get_auth_token():
|
|||||||
try:
|
try:
|
||||||
httpclient.authenticate()
|
httpclient.authenticate()
|
||||||
except (q_exc.Unauthorized, q_exc.Forbidden, q_exc.EndpointNotFound) as e:
|
except (q_exc.Unauthorized, q_exc.Forbidden, q_exc.EndpointNotFound) as e:
|
||||||
LOG.error("authentication failure: %s", e)
|
logger.error("authentication failure: %s", e)
|
||||||
return None
|
return None
|
||||||
# LOG.debug("_get_auth_token: token=%s", httpclient.auth_token)
|
# logger.debug("_get_auth_token: token=%s", httpclient.auth_token)
|
||||||
return httpclient.auth_token
|
return httpclient.auth_token
|
||||||
|
|
||||||
|
|
||||||
@ -126,16 +125,17 @@ class OVSPort(object):
|
|||||||
|
|
||||||
|
|
||||||
class OVSSwitch(object):
|
class OVSSwitch(object):
|
||||||
def __init__(self, dpid, nw, ifaces):
|
def __init__(self, dpid, nw, ifaces, logger):
|
||||||
# TODO: clean up
|
# TODO: clean up
|
||||||
token = None
|
token = None
|
||||||
if CONF.quantum_auth_strategy:
|
if CONF.quantum_auth_strategy:
|
||||||
token = _get_auth_token()
|
token = _get_auth_token(logger)
|
||||||
q_api = _get_quantum_client(token)
|
q_api = _get_quantum_client(token)
|
||||||
|
|
||||||
self.dpid = dpid
|
self.dpid = dpid
|
||||||
self.network_api = nw
|
self.network_api = nw
|
||||||
self.ifaces = ifaces
|
self.ifaces = ifaces
|
||||||
|
self.logger = logger
|
||||||
self.q_api = q_api
|
self.q_api = q_api
|
||||||
self.ctrl_addr = CONF.quantum_controller_addr
|
self.ctrl_addr = CONF.quantum_controller_addr
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ class OVSSwitch(object):
|
|||||||
|
|
||||||
def set_ovsdb_addr(self, dpid, ovsdb_addr):
|
def set_ovsdb_addr(self, dpid, ovsdb_addr):
|
||||||
# easy check if the address format valid
|
# easy check if the address format valid
|
||||||
LOG.debug('set_ovsdb_addr dpid %s ovsdb_addr %s',
|
self.logger.debug('set_ovsdb_addr dpid %s ovsdb_addr %s',
|
||||||
dpid_lib.dpid_to_str(dpid), ovsdb_addr)
|
dpid_lib.dpid_to_str(dpid), ovsdb_addr)
|
||||||
_proto, _host, _port = ovsdb_addr.split(':')
|
_proto, _host, _port = ovsdb_addr.split(':')
|
||||||
|
|
||||||
@ -164,7 +164,7 @@ class OVSSwitch(object):
|
|||||||
return
|
return
|
||||||
self.ovsdb_addr = ovsdb_addr
|
self.ovsdb_addr = ovsdb_addr
|
||||||
if self.ovs_bridge is None:
|
if self.ovs_bridge is None:
|
||||||
LOG.debug('ovsdb: adding ports %s', self.ports)
|
self.logger.debug('ovsdb: adding ports %s', self.ports)
|
||||||
ovs_bridge = bridge.OVSBridge(dpid, ovsdb_addr)
|
ovs_bridge = bridge.OVSBridge(dpid, ovsdb_addr)
|
||||||
self.ovs_bridge = ovs_bridge
|
self.ovs_bridge = ovs_bridge
|
||||||
ovs_bridge.init()
|
ovs_bridge.init()
|
||||||
@ -172,7 +172,7 @@ class OVSSwitch(object):
|
|||||||
# not overwrite controllers, but append this controller
|
# not overwrite controllers, but append this controller
|
||||||
ovs_bridge.set_controller([self.ctrl_addr])
|
ovs_bridge.set_controller([self.ctrl_addr])
|
||||||
for port in self.ports.values():
|
for port in self.ports.values():
|
||||||
LOG.debug('adding port %s', port)
|
self.logger.debug('adding port %s', port)
|
||||||
self.update_port(port.ofport, port.name, True)
|
self.update_port(port.ofport, port.name, True)
|
||||||
|
|
||||||
def _update_external_port(self, port, add=True):
|
def _update_external_port(self, port, add=True):
|
||||||
@ -184,7 +184,7 @@ class OVSSwitch(object):
|
|||||||
self.dpid, port.ofport)
|
self.dpid, port.ofport)
|
||||||
|
|
||||||
def _update_vif_port(self, port, add=True):
|
def _update_vif_port(self, port, add=True):
|
||||||
LOG.debug("_update_vif_port: %s %s", port, add)
|
self.logger.debug("_update_vif_port: %s %s", port, add)
|
||||||
iface_id = port.ext_ids.get('iface-id')
|
iface_id = port.ext_ids.get('iface-id')
|
||||||
if iface_id is None:
|
if iface_id is None:
|
||||||
return
|
return
|
||||||
@ -223,12 +223,12 @@ class OVSSwitch(object):
|
|||||||
'deleted': True
|
'deleted': True
|
||||||
}
|
}
|
||||||
body = {'port': port_data}
|
body = {'port': port_data}
|
||||||
# LOG.debug("port-body = %s", body)
|
# self.logger.debug("port-body = %s", body)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.q_api.update_port(port.ext_ids['iface-id'], body)
|
self.q_api.update_port(port.ext_ids['iface-id'], body)
|
||||||
except (q_exc.ConnectionFailed, q_exc.QuantumClientException) as e:
|
except (q_exc.ConnectionFailed, q_exc.QuantumClientException) as e:
|
||||||
LOG.error("quantum update port failed: %s", e)
|
self.logger.error("quantum update port failed: %s", e)
|
||||||
# TODO: When authentication failure occurred,
|
# TODO: When authentication failure occurred,
|
||||||
# it should get auth token again
|
# it should get auth token again
|
||||||
return
|
return
|
||||||
@ -242,7 +242,8 @@ class OVSSwitch(object):
|
|||||||
mac_lib.haddr_to_bin(mac))
|
mac_lib.haddr_to_bin(mac))
|
||||||
|
|
||||||
def update_port(self, port_no, port_name, add):
|
def update_port(self, port_no, port_name, add):
|
||||||
LOG.debug('update_port port_no %d %s %s', port_no, port_name, add)
|
self.logger.debug('update_port port_no %d %s %s', port_no, port_name,
|
||||||
|
add)
|
||||||
assert port_name is not None
|
assert port_name is not None
|
||||||
old_port = self.ports.get(port_no)
|
old_port = self.ports.get(port_no)
|
||||||
if not add:
|
if not add:
|
||||||
@ -256,12 +257,12 @@ class OVSSwitch(object):
|
|||||||
if 'ofport' not in port_cfg or not port_cfg['ofport']:
|
if 'ofport' not in port_cfg or not port_cfg['ofport']:
|
||||||
port_cfg['ofport'] = port_no
|
port_cfg['ofport'] = port_no
|
||||||
elif port_cfg['ofport'] != port_no:
|
elif port_cfg['ofport'] != port_no:
|
||||||
LOG.warn('inconsistent port_no: %d port_cfg %s',
|
self.logger.warn('inconsistent port_no: %d port_cfg '
|
||||||
port_no, port_cfg)
|
'%s', port_no, port_cfg)
|
||||||
return
|
return
|
||||||
if port_cfg['name'] != port_name:
|
if port_cfg['name'] != port_name:
|
||||||
LOG.warn('inconsistent port_name: %s port_cfg %s',
|
self.logger.warn('inconsistent port_name: %s '
|
||||||
port_name, port_cfg)
|
'port_cfg %s', port_name, port_cfg)
|
||||||
return
|
return
|
||||||
new_port.update(port_cfg)
|
new_port.update(port_cfg)
|
||||||
|
|
||||||
@ -281,10 +282,10 @@ class OVSSwitch(object):
|
|||||||
if port_type == OVSPort.PORT_ERROR:
|
if port_type == OVSPort.PORT_ERROR:
|
||||||
return
|
return
|
||||||
elif port_type == OVSPort.PORT_UNKNOWN:
|
elif port_type == OVSPort.PORT_UNKNOWN:
|
||||||
# LOG.info("delete external port: %s", old_port)
|
# self.logger.info("delete external port: %s", old_port)
|
||||||
self._update_external_port(old_port, add=False)
|
self._update_external_port(old_port, add=False)
|
||||||
else:
|
else:
|
||||||
# LOG.info("delete port: %s", old_port)
|
# self.logger.info("delete port: %s", old_port)
|
||||||
if port_type != OVSPort.PORT_TUNNEL:
|
if port_type != OVSPort.PORT_TUNNEL:
|
||||||
self._update_vif_port(old_port, add=False)
|
self._update_vif_port(old_port, add=False)
|
||||||
return
|
return
|
||||||
@ -296,17 +297,17 @@ class OVSSwitch(object):
|
|||||||
if port_type == OVSPort.PORT_ERROR:
|
if port_type == OVSPort.PORT_ERROR:
|
||||||
return
|
return
|
||||||
elif port_type == OVSPort.PORT_UNKNOWN:
|
elif port_type == OVSPort.PORT_UNKNOWN:
|
||||||
# LOG.info("create external port: %s", new_port)
|
# self.logger.info("create external port: %s", new_port)
|
||||||
self._update_external_port(new_port)
|
self._update_external_port(new_port)
|
||||||
else:
|
else:
|
||||||
# LOG.info("create port: %s", new_port)
|
# self.logger.info("create port: %s", new_port)
|
||||||
if port_type != OVSPort.PORT_TUNNEL:
|
if port_type != OVSPort.PORT_TUNNEL:
|
||||||
self._update_vif_port(new_port)
|
self._update_vif_port(new_port)
|
||||||
return
|
return
|
||||||
if new_port.get_port_type() in (OVSPort.PORT_GUEST,
|
if new_port.get_port_type() in (OVSPort.PORT_GUEST,
|
||||||
OVSPort.PORT_GATEWAY,
|
OVSPort.PORT_GATEWAY,
|
||||||
OVSPort.PORT_VETH_GATEWAY):
|
OVSPort.PORT_VETH_GATEWAY):
|
||||||
# LOG.info("update port: %s", new_port)
|
# self.logger.info("update port: %s", new_port)
|
||||||
self._update_vif_port(new_port)
|
self._update_vif_port(new_port)
|
||||||
|
|
||||||
|
|
||||||
@ -334,10 +335,10 @@ class QuantumAdapter(app_manager.RyuApp):
|
|||||||
ovs_switch = self.dps.get(dpid)
|
ovs_switch = self.dps.get(dpid)
|
||||||
if not ovs_switch:
|
if not ovs_switch:
|
||||||
if create:
|
if create:
|
||||||
ovs_switch = OVSSwitch(dpid, self.nw, self.ifaces)
|
ovs_switch = OVSSwitch(dpid, self.nw, self.ifaces, self.logger)
|
||||||
self.dps[dpid] = ovs_switch
|
self.dps[dpid] = ovs_switch
|
||||||
else:
|
else:
|
||||||
LOG.debug('ovs switch %s is already known', dpid)
|
self.logger.debug('ovs switch %s is already known', dpid)
|
||||||
return ovs_switch
|
return ovs_switch
|
||||||
|
|
||||||
def _port_handler(self, dpid, port_no, port_name, add):
|
def _port_handler(self, dpid, port_no, port_name, add):
|
||||||
@ -345,7 +346,7 @@ class QuantumAdapter(app_manager.RyuApp):
|
|||||||
if ovs_switch:
|
if ovs_switch:
|
||||||
ovs_switch.update_port(port_no, port_name, add)
|
ovs_switch.update_port(port_no, port_name, add)
|
||||||
else:
|
else:
|
||||||
LOG.warn('unknown ovs switch %s %s %s %s\n',
|
self.logger.warn('unknown ovs switch %s %s %s %s\n',
|
||||||
dpid, port_no, port_name, add)
|
dpid, port_no, port_name, add)
|
||||||
|
|
||||||
@handler.set_ev_cls(dpset.EventDP)
|
@handler.set_ev_cls(dpset.EventDP)
|
||||||
@ -388,24 +389,24 @@ class QuantumAdapter(app_manager.RyuApp):
|
|||||||
|
|
||||||
@handler.set_ev_cls(conf_switch.EventConfSwitchSet)
|
@handler.set_ev_cls(conf_switch.EventConfSwitchSet)
|
||||||
def conf_switch_set_handler(self, ev):
|
def conf_switch_set_handler(self, ev):
|
||||||
LOG.debug("conf_switch set: %s", ev)
|
self.logger.debug("conf_switch set: %s", ev)
|
||||||
if ev.key == cs_key.OVSDB_ADDR:
|
if ev.key == cs_key.OVSDB_ADDR:
|
||||||
self._conf_switch_set_ovsdb_addr(ev.dpid, ev.value)
|
self._conf_switch_set_ovsdb_addr(ev.dpid, ev.value)
|
||||||
else:
|
else:
|
||||||
LOG.debug("unknown event: %s", ev)
|
self.logger.debug("unknown event: %s", ev)
|
||||||
|
|
||||||
@handler.set_ev_cls(conf_switch.EventConfSwitchDel)
|
@handler.set_ev_cls(conf_switch.EventConfSwitchDel)
|
||||||
def conf_switch_del_handler(self, ev):
|
def conf_switch_del_handler(self, ev):
|
||||||
LOG.debug("conf_switch del: %s", ev)
|
self.logger.debug("conf_switch del: %s", ev)
|
||||||
if ev.key == cs_key.OVSDB_ADDR:
|
if ev.key == cs_key.OVSDB_ADDR:
|
||||||
self._conf_switch_del_ovsdb_addr(ev.dpid)
|
self._conf_switch_del_ovsdb_addr(ev.dpid)
|
||||||
else:
|
else:
|
||||||
LOG.debug("unknown event: %s", ev)
|
self.logger.debug("unknown event: %s", ev)
|
||||||
|
|
||||||
@handler.set_ev_cls(quantum_ifaces.EventQuantumIfaceSet)
|
@handler.set_ev_cls(quantum_ifaces.EventQuantumIfaceSet)
|
||||||
def quantum_iface_set_handler(self, ev):
|
def quantum_iface_set_handler(self, ev):
|
||||||
if ev.key != quantum_ifaces.QuantumIfaces.KEY_NETWORK_ID:
|
if ev.key != quantum_ifaces.QuantumIfaces.KEY_NETWORK_ID:
|
||||||
# LOG.debug("unknown key %s", ev.key)
|
# self.logger.debug("unknown key %s", ev.key)
|
||||||
return
|
return
|
||||||
iface_id = ev.iface_id
|
iface_id = ev.iface_id
|
||||||
try:
|
try:
|
||||||
|
@ -34,9 +34,6 @@ from ryu.lib.mac import haddr_to_str
|
|||||||
from ryu.lib import mac
|
from ryu.lib import mac
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger('ryu.app.simple_isolation')
|
|
||||||
|
|
||||||
|
|
||||||
class SimpleIsolation(app_manager.RyuApp):
|
class SimpleIsolation(app_manager.RyuApp):
|
||||||
_CONTEXTS = {
|
_CONTEXTS = {
|
||||||
'network': network.Network,
|
'network': network.Network,
|
||||||
@ -88,13 +85,14 @@ class SimpleIsolation(app_manager.RyuApp):
|
|||||||
|
|
||||||
if not self.nw.same_network(datapath.id, nw_id, out_port,
|
if not self.nw.same_network(datapath.id, nw_id, out_port,
|
||||||
NW_ID_EXTERNAL):
|
NW_ID_EXTERNAL):
|
||||||
LOG.debug('packet is blocked src %s dst %s '
|
self.logger.debug('packet is blocked src %s dst %s '
|
||||||
'from %d to %d on datapath %d',
|
'from %d to %d on datapath %d',
|
||||||
haddr_to_str(src), haddr_to_str(dst),
|
haddr_to_str(src), haddr_to_str(dst),
|
||||||
msg.in_port, out_port, datapath.id)
|
msg.in_port, out_port, datapath.id)
|
||||||
return
|
return
|
||||||
|
|
||||||
LOG.debug("learned dpid %s in_port %d out_port %d src %s dst %s",
|
self.logger.debug("learned dpid %s in_port %d out_port "
|
||||||
|
"%d src %s dst %s",
|
||||||
datapath.id, msg.in_port, out_port,
|
datapath.id, msg.in_port, out_port,
|
||||||
haddr_to_str(src), haddr_to_str(dst))
|
haddr_to_str(src), haddr_to_str(dst))
|
||||||
actions = [datapath.ofproto_parser.OFPActionOutput(out_port)]
|
actions = [datapath.ofproto_parser.OFPActionOutput(out_port)]
|
||||||
@ -103,13 +101,13 @@ class SimpleIsolation(app_manager.RyuApp):
|
|||||||
def _flood_to_nw_id(self, msg, src, dst, nw_id):
|
def _flood_to_nw_id(self, msg, src, dst, nw_id):
|
||||||
datapath = msg.datapath
|
datapath = msg.datapath
|
||||||
actions = []
|
actions = []
|
||||||
LOG.debug("dpid %s in_port %d src %s dst %s ports %s",
|
self.logger.debug("dpid %s in_port %d src %s dst %s ports %s",
|
||||||
datapath.id, msg.in_port,
|
datapath.id, msg.in_port,
|
||||||
haddr_to_str(src), haddr_to_str(dst),
|
haddr_to_str(src), haddr_to_str(dst),
|
||||||
self.nw.dpids.get(datapath.id, {}).items())
|
self.nw.dpids.get(datapath.id, {}).items())
|
||||||
for port_no in self.nw.filter_ports(datapath.id, msg.in_port,
|
for port_no in self.nw.filter_ports(datapath.id, msg.in_port,
|
||||||
nw_id, NW_ID_EXTERNAL):
|
nw_id, NW_ID_EXTERNAL):
|
||||||
LOG.debug("port_no %s", port_no)
|
self.logger.debug("port_no %s", port_no)
|
||||||
actions.append(datapath.ofproto_parser.OFPActionOutput(port_no))
|
actions.append(datapath.ofproto_parser.OFPActionOutput(port_no))
|
||||||
self._modflow_and_send_packet(msg, src, dst, actions)
|
self._modflow_and_send_packet(msg, src, dst, actions)
|
||||||
|
|
||||||
@ -129,7 +127,7 @@ class SimpleIsolation(app_manager.RyuApp):
|
|||||||
|
|
||||||
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
|
@set_ev_cls(ofp_event.EventOFPPacketIn, MAIN_DISPATCHER)
|
||||||
def packet_in_handler(self, ev):
|
def packet_in_handler(self, ev):
|
||||||
# LOG.debug('packet in ev %s msg %s', ev, ev.msg)
|
# self.logger.debug('packet in ev %s msg %s', ev, ev.msg)
|
||||||
msg = ev.msg
|
msg = ev.msg
|
||||||
datapath = msg.datapath
|
datapath = msg.datapath
|
||||||
ofproto = datapath.ofproto
|
ofproto = datapath.ofproto
|
||||||
@ -151,7 +149,7 @@ class SimpleIsolation(app_manager.RyuApp):
|
|||||||
# allow external -> known nw id change
|
# allow external -> known nw id change
|
||||||
self.mac2net.add_mac(src, port_nw_id, NW_ID_EXTERNAL)
|
self.mac2net.add_mac(src, port_nw_id, NW_ID_EXTERNAL)
|
||||||
except MacAddressDuplicated:
|
except MacAddressDuplicated:
|
||||||
LOG.warn('mac address %s is already in use.'
|
self.logger.warn('mac address %s is already in use.'
|
||||||
' So (dpid %s, port %s) can not use it',
|
' So (dpid %s, port %s) can not use it',
|
||||||
haddr_to_str(src), datapath.id, msg.in_port)
|
haddr_to_str(src), datapath.id, msg.in_port)
|
||||||
#
|
#
|
||||||
@ -241,7 +239,7 @@ class SimpleIsolation(app_manager.RyuApp):
|
|||||||
out_port)
|
out_port)
|
||||||
else:
|
else:
|
||||||
# should not occur?
|
# should not occur?
|
||||||
LOG.debug("should this case happen?")
|
self.logger.debug("should this case happen?")
|
||||||
self._drop_packet(msg)
|
self._drop_packet(msg)
|
||||||
elif dst_nw_id == NW_ID_EXTERNAL:
|
elif dst_nw_id == NW_ID_EXTERNAL:
|
||||||
# try learned mac
|
# try learned mac
|
||||||
@ -251,7 +249,7 @@ class SimpleIsolation(app_manager.RyuApp):
|
|||||||
src_nw_id, out_port)
|
src_nw_id, out_port)
|
||||||
else:
|
else:
|
||||||
assert dst_nw_id == NW_ID_UNKNOWN
|
assert dst_nw_id == NW_ID_UNKNOWN
|
||||||
LOG.debug("Unknown dst_nw_id")
|
self.logger.debug("Unknown dst_nw_id")
|
||||||
self._drop_packet(msg)
|
self._drop_packet(msg)
|
||||||
elif src_nw_id == NW_ID_EXTERNAL:
|
elif src_nw_id == NW_ID_EXTERNAL:
|
||||||
self._modflow_and_drop_packet(msg, src, dst)
|
self._modflow_and_drop_packet(msg, src, dst)
|
||||||
@ -263,7 +261,7 @@ class SimpleIsolation(app_manager.RyuApp):
|
|||||||
# drop packets
|
# drop packets
|
||||||
assert port_nw_id == NW_ID_UNKNOWN
|
assert port_nw_id == NW_ID_UNKNOWN
|
||||||
self._drop_packet(msg)
|
self._drop_packet(msg)
|
||||||
# LOG.debug("Unknown port_nw_id")
|
# self.logger.debug("Unknown port_nw_id")
|
||||||
|
|
||||||
def _port_add(self, ev):
|
def _port_add(self, ev):
|
||||||
#
|
#
|
||||||
|
@ -25,8 +25,6 @@ from ryu.ofproto import ofproto_v1_0
|
|||||||
from ryu.lib.mac import haddr_to_str
|
from ryu.lib.mac import haddr_to_str
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger('ryu.app.simple_switch')
|
|
||||||
|
|
||||||
# TODO: we should split the handler into two parts, protocol
|
# TODO: we should split the handler into two parts, protocol
|
||||||
# independent and dependant parts.
|
# independent and dependant parts.
|
||||||
|
|
||||||
@ -71,8 +69,9 @@ class SimpleSwitch(app_manager.RyuApp):
|
|||||||
dpid = datapath.id
|
dpid = datapath.id
|
||||||
self.mac_to_port.setdefault(dpid, {})
|
self.mac_to_port.setdefault(dpid, {})
|
||||||
|
|
||||||
LOG.info("packet in %s %s %s %s",
|
self.logger.info("packet in %s %s %s %s",
|
||||||
dpid, haddr_to_str(src), haddr_to_str(dst), msg.in_port)
|
dpid, haddr_to_str(src), haddr_to_str(dst),
|
||||||
|
msg.in_port)
|
||||||
|
|
||||||
# learn a mac address to avoid FLOOD next time.
|
# learn a mac address to avoid FLOOD next time.
|
||||||
self.mac_to_port[dpid][src] = msg.in_port
|
self.mac_to_port[dpid][src] = msg.in_port
|
||||||
@ -101,10 +100,10 @@ class SimpleSwitch(app_manager.RyuApp):
|
|||||||
|
|
||||||
ofproto = msg.datapath.ofproto
|
ofproto = msg.datapath.ofproto
|
||||||
if reason == ofproto.OFPPR_ADD:
|
if reason == ofproto.OFPPR_ADD:
|
||||||
LOG.info("port added %s", port_no)
|
self.logger.info("port added %s", port_no)
|
||||||
elif reason == ofproto.OFPPR_DELETE:
|
elif reason == ofproto.OFPPR_DELETE:
|
||||||
LOG.info("port deleted %s", port_no)
|
self.logger.info("port deleted %s", port_no)
|
||||||
elif reason == ofproto.OFPPR_MODIFY:
|
elif reason == ofproto.OFPPR_MODIFY:
|
||||||
LOG.info("port modified %s", port_no)
|
self.logger.info("port modified %s", port_no)
|
||||||
else:
|
else:
|
||||||
LOG.info("Illeagal port state %s %s", port_no, reason)
|
self.logger.info("Illeagal port state %s %s", port_no, reason)
|
||||||
|
@ -31,9 +31,6 @@ from ryu.lib.ovs import bridge
|
|||||||
from ryu.ofproto import nx_match
|
from ryu.ofproto import nx_match
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
def _is_reserved_port(dp, port_no):
|
def _is_reserved_port(dp, port_no):
|
||||||
return port_no > dp.ofproto.OFPP_MAX
|
return port_no > dp.ofproto.OFPP_MAX
|
||||||
|
|
||||||
@ -60,7 +57,7 @@ class SimpleVLAN(app_manager.RyuApp):
|
|||||||
self.tunnels = kwargs['tunnels']
|
self.tunnels = kwargs['tunnels']
|
||||||
|
|
||||||
def _port_flow_add(self, dp, port_no):
|
def _port_flow_add(self, dp, port_no):
|
||||||
LOG.debug('ovs_port_update dpid %s port_no %s',
|
self.logger.debug('ovs_port_update dpid %s port_no %s',
|
||||||
dpid_lib.dpid_to_str(dp.id), port_no)
|
dpid_lib.dpid_to_str(dp.id), port_no)
|
||||||
rule = nx_match.ClsRule()
|
rule = nx_match.ClsRule()
|
||||||
rule.set_in_port(port_no)
|
rule.set_in_port(port_no)
|
||||||
@ -72,7 +69,7 @@ class SimpleVLAN(app_manager.RyuApp):
|
|||||||
priority=self._PRIORITY_NORMAL, actions=actions)
|
priority=self._PRIORITY_NORMAL, actions=actions)
|
||||||
|
|
||||||
def _port_flow_del(self, dp, port_no):
|
def _port_flow_del(self, dp, port_no):
|
||||||
LOG.debug('_port_flow_del dp %s port_no %d',
|
self.logger.debug('_port_flow_del dp %s port_no %d',
|
||||||
dpid_lib.dpid_to_str(dp.id), port_no)
|
dpid_lib.dpid_to_str(dp.id), port_no)
|
||||||
rule = nx_match.ClsRule()
|
rule = nx_match.ClsRule()
|
||||||
rule.set_in_port(port_no)
|
rule.set_in_port(port_no)
|
||||||
@ -115,18 +112,18 @@ class SimpleVLAN(app_manager.RyuApp):
|
|||||||
try:
|
try:
|
||||||
port = self.dpset.get_port(dpid, port_no)
|
port = self.dpset.get_port(dpid, port_no)
|
||||||
except ryu_exc.PortNotFound:
|
except ryu_exc.PortNotFound:
|
||||||
LOG.debug('port not found')
|
self.logger.debug('port not found')
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ovsdb_addr = self.conf_sw.get_key(dpid, conf_switch_key.OVSDB_ADDR)
|
ovsdb_addr = self.conf_sw.get_key(dpid, conf_switch_key.OVSDB_ADDR)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
LOG.debug('ovsdb_addr not found')
|
self.logger.debug('ovsdb_addr not found')
|
||||||
return
|
return
|
||||||
|
|
||||||
self._port_flow_add(dp, port_no)
|
self._port_flow_add(dp, port_no)
|
||||||
|
|
||||||
LOG.debug('ovs_port_update dpid %s port_no %s', dpid, port_no)
|
self.logger.debug('ovs_port_update dpid %s port_no %s', dpid, port_no)
|
||||||
# ovs-vsctl --db=ovsdb_addr --timeout=2
|
# ovs-vsctl --db=ovsdb_addr --timeout=2
|
||||||
# set Port port.name tag=tunnel_key
|
# set Port port.name tag=tunnel_key
|
||||||
ovs_br = bridge.OVSBridge(dpid, ovsdb_addr, 2)
|
ovs_br = bridge.OVSBridge(dpid, ovsdb_addr, 2)
|
||||||
@ -135,30 +132,30 @@ class SimpleVLAN(app_manager.RyuApp):
|
|||||||
try:
|
try:
|
||||||
ovs_br.set_db_attribute("Port", port_name, "tag", tunnel_key)
|
ovs_br.set_db_attribute("Port", port_name, "tag", tunnel_key)
|
||||||
except gevent.Timeout:
|
except gevent.Timeout:
|
||||||
LOG.error('timout')
|
self.logger.error('timout')
|
||||||
return
|
return
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def _port_setup_netid(self, dpid, port_no, network_id):
|
def _port_setup_netid(self, dpid, port_no, network_id):
|
||||||
LOG.debug('_port_setup_netid %s %s %s',
|
self.logger.debug('_port_setup_netid %s %s %s',
|
||||||
dpid_lib.dpid_to_str(dpid), port_no, network_id)
|
dpid_lib.dpid_to_str(dpid), port_no, network_id)
|
||||||
dp = self.dpset.get(dpid)
|
dp = self.dpset.get(dpid)
|
||||||
if dp is None:
|
if dp is None:
|
||||||
LOG.debug('dp not found')
|
self.logger.debug('dp not found')
|
||||||
return
|
return
|
||||||
if _is_reserved_port(dp, port_no):
|
if _is_reserved_port(dp, port_no):
|
||||||
return
|
return
|
||||||
|
|
||||||
if network_id == rest_nw_id.NW_ID_EXTERNAL:
|
if network_id == rest_nw_id.NW_ID_EXTERNAL:
|
||||||
LOG.debug('external interface')
|
self.logger.debug('external interface')
|
||||||
self._queue_port_flow_add(dp, port_no)
|
self._queue_port_flow_add(dp, port_no)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
tunnel_key = self.tunnels.get_key(network_id)
|
tunnel_key = self.tunnels.get_key(network_id)
|
||||||
except tunnels.TunnelKeyNotFound:
|
except tunnels.TunnelKeyNotFound:
|
||||||
LOG.debug('tunnel key not found')
|
self.logger.debug('tunnel key not found')
|
||||||
return
|
return
|
||||||
|
|
||||||
return self._port_setup(dp, port_no, tunnel_key)
|
return self._port_setup(dp, port_no, tunnel_key)
|
||||||
@ -171,22 +168,22 @@ class SimpleVLAN(app_manager.RyuApp):
|
|||||||
try:
|
try:
|
||||||
network_id = self.nw.get_network(dpid, port_no)
|
network_id = self.nw.get_network(dpid, port_no)
|
||||||
except ryu_exc.PortUnknown:
|
except ryu_exc.PortUnknown:
|
||||||
LOG.debug('port_unknown')
|
self.logger.debug('port_unknown')
|
||||||
self._queue_port_flow_del(dp, port_no)
|
self._queue_port_flow_del(dp, port_no)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self._port_setup_netid(dpid, port_no, network_id):
|
if not self._port_setup_netid(dpid, port_no, network_id):
|
||||||
LOG.debug('_port_setup_netid failed')
|
self.logger.debug('_port_setup_netid failed')
|
||||||
self._queue_port_flow_del(dp, port_no)
|
self._queue_port_flow_del(dp, port_no)
|
||||||
|
|
||||||
@handler.set_ev_cls(dpset.EventPortAdd)
|
@handler.set_ev_cls(dpset.EventPortAdd)
|
||||||
def port_add_handler(self, ev):
|
def port_add_handler(self, ev):
|
||||||
LOG.debug('port_add %s', ev)
|
self.logger.debug('port_add %s', ev)
|
||||||
self._port_add(ev.dp, ev.port.port_no)
|
self._port_add(ev.dp, ev.port.port_no)
|
||||||
|
|
||||||
@handler.set_ev_cls(dpset.EventPortDelete)
|
@handler.set_ev_cls(dpset.EventPortDelete)
|
||||||
def port_del_handler(self, ev):
|
def port_del_handler(self, ev):
|
||||||
LOG.debug('port_del %s', ev)
|
self.logger.debug('port_del %s', ev)
|
||||||
dp = ev.dp
|
dp = ev.dp
|
||||||
port_no = ev.port.port_no
|
port_no = ev.port.port_no
|
||||||
if _is_reserved_port(dp, port_no):
|
if _is_reserved_port(dp, port_no):
|
||||||
@ -195,14 +192,14 @@ class SimpleVLAN(app_manager.RyuApp):
|
|||||||
|
|
||||||
@handler.set_ev_cls(network.EventNetworkPort)
|
@handler.set_ev_cls(network.EventNetworkPort)
|
||||||
def network_port_handler(self, ev):
|
def network_port_handler(self, ev):
|
||||||
LOG.debug('network_port %s', ev)
|
self.logger.debug('network_port %s', ev)
|
||||||
if not ev.add_del:
|
if not ev.add_del:
|
||||||
return
|
return
|
||||||
self._port_setup_netid(ev.dpid, ev.port_no, ev.network_id)
|
self._port_setup_netid(ev.dpid, ev.port_no, ev.network_id)
|
||||||
|
|
||||||
@handler.set_ev_cls(tunnels.EventTunnelKeyAdd)
|
@handler.set_ev_cls(tunnels.EventTunnelKeyAdd)
|
||||||
def tunnel_key_add_handler(self, ev):
|
def tunnel_key_add_handler(self, ev):
|
||||||
LOG.debug('tunnel_add %s', ev)
|
self.logger.debug('tunnel_add %s', ev)
|
||||||
tunnel_key = ev.tunnel_key
|
tunnel_key = ev.tunnel_key
|
||||||
for (dpid, port_no) in self.nw.list_ports(ev.network_id):
|
for (dpid, port_no) in self.nw.list_ports(ev.network_id):
|
||||||
dp = self.dpset.get(dpid)
|
dp = self.dpset.get(dpid)
|
||||||
@ -212,7 +209,7 @@ class SimpleVLAN(app_manager.RyuApp):
|
|||||||
|
|
||||||
@handler.set_ev_cls(conf_switch.EventConfSwitchSet)
|
@handler.set_ev_cls(conf_switch.EventConfSwitchSet)
|
||||||
def conf_switch_set_handler(self, ev):
|
def conf_switch_set_handler(self, ev):
|
||||||
LOG.debug('conf_switch_set %s', ev)
|
self.logger.debug('conf_switch_set %s', ev)
|
||||||
if ev.key != conf_switch_key.OVSDB_ADDR:
|
if ev.key != conf_switch_key.OVSDB_ADDR:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -32,7 +32,6 @@ from ryu.lib import dpid as dpid_lib
|
|||||||
from ryu.lib.ovs import bridge as ovs_bridge
|
from ryu.lib.ovs import bridge as ovs_bridge
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
|
||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
CONF.register_opts([
|
CONF.register_opts([
|
||||||
cfg.StrOpt('tunnel-type', default='gre',
|
cfg.StrOpt('tunnel-type', default='gre',
|
||||||
@ -104,11 +103,12 @@ class TunnelPort(object):
|
|||||||
|
|
||||||
class TunnelDP(object):
|
class TunnelDP(object):
|
||||||
def __init__(self, dpid, ovsdb_addr, tunnel_ip, tunnel_type, conf_switch_,
|
def __init__(self, dpid, ovsdb_addr, tunnel_ip, tunnel_type, conf_switch_,
|
||||||
network_api, tunnel_api):
|
network_api, tunnel_api, logger):
|
||||||
super(TunnelDP, self).__init__()
|
super(TunnelDP, self).__init__()
|
||||||
self.dpid = dpid
|
self.dpid = dpid
|
||||||
self.network_api = network_api
|
self.network_api = network_api
|
||||||
self.tunnel_api = tunnel_api
|
self.tunnel_api = tunnel_api
|
||||||
|
self.logger = logger
|
||||||
|
|
||||||
self.ovs_bridge = ovs_bridge.OVSBridge(dpid, ovsdb_addr)
|
self.ovs_bridge = ovs_bridge.OVSBridge(dpid, ovsdb_addr)
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ class TunnelDP(object):
|
|||||||
self.ovs_bridge.init()
|
self.ovs_bridge.init()
|
||||||
for tp in self.ovs_bridge.get_tunnel_ports(self.tunnel_type):
|
for tp in self.ovs_bridge.get_tunnel_ports(self.tunnel_type):
|
||||||
if tp.local_ip != self.tunnel_ip:
|
if tp.local_ip != self.tunnel_ip:
|
||||||
LOG.warn('unknown tunnel port %s', tp)
|
self.logger.warn('unknown tunnel port %s', tp)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
remote_dpid = self.conf_switch.find_dpid(cs_key.OVS_TUNNEL_ADDR,
|
remote_dpid = self.conf_switch.find_dpid(cs_key.OVS_TUNNEL_ADDR,
|
||||||
@ -155,7 +155,7 @@ class TunnelDP(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
# tunnel ip address is changed.
|
# tunnel ip address is changed.
|
||||||
LOG.warn('local ip address is changed %s: %s -> %s',
|
self.logger.warn('local ip address is changed %s: %s -> %s',
|
||||||
dpid_lib.dpid_to_str(remote_dpid),
|
dpid_lib.dpid_to_str(remote_dpid),
|
||||||
self.tunnel_ip, remote_ip)
|
self.tunnel_ip, remote_ip)
|
||||||
# recreate tunnel ports.
|
# recreate tunnel ports.
|
||||||
@ -171,7 +171,7 @@ class TunnelDP(object):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.tunnel_ip == remote_ip:
|
if self.tunnel_ip == remote_ip:
|
||||||
LOG.error('ip conflict: %s %s %s',
|
self.logger.error('ip conflict: %s %s %s',
|
||||||
dpid_lib.dpid_to_str(self.dpid),
|
dpid_lib.dpid_to_str(self.dpid),
|
||||||
dpid_lib.dpid_to_str(remote_dpid), remote_ip)
|
dpid_lib.dpid_to_str(remote_dpid), remote_ip)
|
||||||
# XXX What should we do?
|
# XXX What should we do?
|
||||||
@ -183,7 +183,7 @@ class TunnelDP(object):
|
|||||||
self._api_update(tp.port_no, remote_dpid)
|
self._api_update(tp.port_no, remote_dpid)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
LOG.warn('remote ip address is changed %s: %s -> %s',
|
self.logger.warn('remote ip address is changed %s: %s -> %s',
|
||||||
dpid_lib.dpid_to_str(remote_dpid),
|
dpid_lib.dpid_to_str(remote_dpid),
|
||||||
tp.remote_ip, remote_ip)
|
tp.remote_ip, remote_ip)
|
||||||
self._del_tunnel_port(tp.port_no, self.tunnel_ip, tp.remote_ip)
|
self._del_tunnel_port(tp.port_no, self.tunnel_ip, tp.remote_ip)
|
||||||
@ -215,14 +215,14 @@ class TunnelDP(object):
|
|||||||
for tp in self.tunnels.values())
|
for tp in self.tunnels.values())
|
||||||
|
|
||||||
def _add_tunnel_port(self, remote_dpid, remote_ip):
|
def _add_tunnel_port(self, remote_dpid, remote_ip):
|
||||||
LOG.debug('add_tunnel_port local %s %s remote %s %s',
|
self.logger.debug('add_tunnel_port local %s %s remote %s %s',
|
||||||
dpid_lib.dpid_to_str(self.dpid), self.tunnel_ip,
|
dpid_lib.dpid_to_str(self.dpid), self.tunnel_ip,
|
||||||
dpid_lib.dpid_to_str(remote_dpid), remote_ip)
|
dpid_lib.dpid_to_str(remote_dpid), remote_ip)
|
||||||
if self._tunnel_port_exists(remote_dpid, remote_ip):
|
if self._tunnel_port_exists(remote_dpid, remote_ip):
|
||||||
LOG.debug('add_tunnel_port nop')
|
self.logger.debug('add_tunnel_port nop')
|
||||||
return
|
return
|
||||||
|
|
||||||
LOG.debug('add_tunnel_port creating port')
|
self.logger.debug('add_tunnel_port creating port')
|
||||||
port_name = self._port_name(self.tunnel_ip, remote_ip)
|
port_name = self._port_name(self.tunnel_ip, remote_ip)
|
||||||
self.ovs_bridge.add_tunnel_port(port_name, self.tunnel_type,
|
self.ovs_bridge.add_tunnel_port(port_name, self.tunnel_type,
|
||||||
self.tunnel_ip, remote_ip, 'flow')
|
self.tunnel_ip, remote_ip, 'flow')
|
||||||
@ -290,7 +290,7 @@ class TunnelDP(object):
|
|||||||
try:
|
try:
|
||||||
self._init()
|
self._init()
|
||||||
except gevent.timeout.Timeout:
|
except gevent.timeout.Timeout:
|
||||||
LOG.warn('_init timeouted')
|
self.logger.warn('_init timeouted')
|
||||||
|
|
||||||
req = None
|
req = None
|
||||||
while True:
|
while True:
|
||||||
@ -305,19 +305,19 @@ class TunnelDP(object):
|
|||||||
|
|
||||||
# shoud use dispatcher?
|
# shoud use dispatcher?
|
||||||
if isinstance(req, self._RequestUpdateRemote):
|
if isinstance(req, self._RequestUpdateRemote):
|
||||||
LOG.debug('update_remote')
|
self.logger.debug('update_remote')
|
||||||
self._update_remote(req.remote_dpid, req.remote_ip)
|
self._update_remote(req.remote_dpid, req.remote_ip)
|
||||||
elif isinstance(req, self._RequestAddTunnelPort):
|
elif isinstance(req, self._RequestAddTunnelPort):
|
||||||
LOG.debug('add_tunnel_port')
|
self.logger.debug('add_tunnel_port')
|
||||||
self._add_tunnel_port(req.remote_dpid, req.remote_ip)
|
self._add_tunnel_port(req.remote_dpid, req.remote_ip)
|
||||||
elif isinstance(req, self._RequestDelTunnelPort):
|
elif isinstance(req, self._RequestDelTunnelPort):
|
||||||
LOG.debug('del_tunnel_port')
|
self.logger.debug('del_tunnel_port')
|
||||||
self._del_tunnel_port_ip(req.remote_ip)
|
self._del_tunnel_port_ip(req.remote_ip)
|
||||||
else:
|
else:
|
||||||
LOG.error('unknown request %s', req)
|
self.logger.error('unknown request %s', req)
|
||||||
except gevent.timeout.Timeout:
|
except gevent.timeout.Timeout:
|
||||||
# timeout. try again
|
# timeout. try again
|
||||||
LOG.warn('timeout try again')
|
self.logger.warn('timeout try again')
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
# Done. move onto next request
|
# Done. move onto next request
|
||||||
@ -369,13 +369,15 @@ class TunnelPortUpdater(app_manager.RyuApp):
|
|||||||
setattr(self, self._LOCK, gevent.coros.Semaphore())
|
setattr(self, self._LOCK, gevent.coros.Semaphore())
|
||||||
|
|
||||||
def _ovsdb_update(self, dpid, ovsdb_addr, ovs_tunnel_addr):
|
def _ovsdb_update(self, dpid, ovsdb_addr, ovs_tunnel_addr):
|
||||||
LOG.debug('_ovsdb_update %s %s %s',
|
self.logger.debug('_ovsdb_update %s %s %s',
|
||||||
dpid_lib.dpid_to_str(dpid), ovsdb_addr, ovs_tunnel_addr)
|
dpid_lib.dpid_to_str(dpid), ovsdb_addr,
|
||||||
|
ovs_tunnel_addr)
|
||||||
if dpid not in self.tunnel_dpset:
|
if dpid not in self.tunnel_dpset:
|
||||||
# TODO:XXX changing ovsdb_addr, ovs_tunnel_addr
|
# TODO:XXX changing ovsdb_addr, ovs_tunnel_addr
|
||||||
tunnel_dp = TunnelDP(dpid, ovsdb_addr, ovs_tunnel_addr,
|
tunnel_dp = TunnelDP(dpid, ovsdb_addr, ovs_tunnel_addr,
|
||||||
self.tunnel_type, self.cs,
|
self.tunnel_type, self.cs,
|
||||||
self.network_api, self.tunnel_api)
|
self.network_api, self.tunnel_api,
|
||||||
|
self.logger)
|
||||||
self.tunnel_dpset[dpid] = tunnel_dp
|
self.tunnel_dpset[dpid] = tunnel_dp
|
||||||
|
|
||||||
tunnel_dp = self.tunnel_dpset.get(dpid)
|
tunnel_dp = self.tunnel_dpset.get(dpid)
|
||||||
@ -385,7 +387,7 @@ class TunnelPortUpdater(app_manager.RyuApp):
|
|||||||
|
|
||||||
@handler.set_ev_cls(conf_switch.EventConfSwitchSet)
|
@handler.set_ev_cls(conf_switch.EventConfSwitchSet)
|
||||||
def conf_switch_set_handler(self, ev):
|
def conf_switch_set_handler(self, ev):
|
||||||
LOG.debug('conf_switch_set_handler %s %s %s',
|
self.logger.debug('conf_switch_set_handler %s %s %s',
|
||||||
dpid_lib.dpid_to_str(ev.dpid), ev.key, ev.value)
|
dpid_lib.dpid_to_str(ev.dpid), ev.key, ev.value)
|
||||||
dpid = ev.dpid
|
dpid = ev.dpid
|
||||||
if (ev.key == cs_key.OVSDB_ADDR or ev.key == cs_key.OVS_TUNNEL_ADDR):
|
if (ev.key == cs_key.OVSDB_ADDR or ev.key == cs_key.OVS_TUNNEL_ADDR):
|
||||||
@ -405,7 +407,7 @@ class TunnelPortUpdater(app_manager.RyuApp):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def _add_tunnel_ports(self, tunnel_dp, remote_dpids):
|
def _add_tunnel_ports(self, tunnel_dp, remote_dpids):
|
||||||
LOG.debug('_add_tunnel_ports %s %s', tunnel_dp, remote_dpids)
|
self.logger.debug('_add_tunnel_ports %s %s', tunnel_dp, remote_dpids)
|
||||||
for remote_dpid in remote_dpids:
|
for remote_dpid in remote_dpids:
|
||||||
remote_dp = self.tunnel_dpset.get(remote_dpid)
|
remote_dp = self.tunnel_dpset.get(remote_dpid)
|
||||||
if remote_dp is None:
|
if remote_dp is None:
|
||||||
@ -416,7 +418,8 @@ class TunnelPortUpdater(app_manager.RyuApp):
|
|||||||
tunnel_dp.tunnel_ip)
|
tunnel_dp.tunnel_ip)
|
||||||
|
|
||||||
def _vm_port_add(self, network_id, dpid):
|
def _vm_port_add(self, network_id, dpid):
|
||||||
LOG.debug('_vm_port_add %s %s', network_id, dpid_lib.dpid_to_str(dpid))
|
self.logger.debug('_vm_port_add %s %s', network_id,
|
||||||
|
dpid_lib.dpid_to_str(dpid))
|
||||||
dpids = self.nw.get_dpids(network_id)
|
dpids = self.nw.get_dpids(network_id)
|
||||||
dpids.remove(dpid)
|
dpids.remove(dpid)
|
||||||
for remote_dpid in dpids:
|
for remote_dpid in dpids:
|
||||||
@ -428,7 +431,8 @@ class TunnelPortUpdater(app_manager.RyuApp):
|
|||||||
self._add_tunnel_ports(tunnel_dp, dpids)
|
self._add_tunnel_ports(tunnel_dp, dpids)
|
||||||
|
|
||||||
def _vm_port_del(self, network_id, dpid):
|
def _vm_port_del(self, network_id, dpid):
|
||||||
LOG.debug('_vm_port_del %s %s', network_id, dpid_lib.dpid_to_str(dpid))
|
self.logger.debug('_vm_port_del %s %s', network_id,
|
||||||
|
dpid_lib.dpid_to_str(dpid))
|
||||||
if len(self.nw.get_ports(dpid, network_id)) > 0:
|
if len(self.nw.get_ports(dpid, network_id)) > 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -459,7 +463,7 @@ class TunnelPortUpdater(app_manager.RyuApp):
|
|||||||
|
|
||||||
@handler.set_ev_cls(network.EventNetworkPort)
|
@handler.set_ev_cls(network.EventNetworkPort)
|
||||||
def network_port_handler(self, ev):
|
def network_port_handler(self, ev):
|
||||||
LOG.debug('network_port_handler %s', ev)
|
self.logger.debug('network_port_handler %s', ev)
|
||||||
if ev.network_id in rest_nw_id.RESERVED_NETWORK_IDS:
|
if ev.network_id in rest_nw_id.RESERVED_NETWORK_IDS:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -63,6 +63,7 @@ class RyuApp(object):
|
|||||||
self.threads = []
|
self.threads = []
|
||||||
self.events = Queue()
|
self.events = Queue()
|
||||||
self.replies = Queue()
|
self.replies = Queue()
|
||||||
|
self.logger = logging.getLogger(self.name)
|
||||||
self.threads.append(gevent.spawn(self._event_loop))
|
self.threads.append(gevent.spawn(self._event_loop))
|
||||||
|
|
||||||
def register_handler(self, ev_cls, handler):
|
def register_handler(self, ev_cls, handler):
|
||||||
|
@ -25,9 +25,6 @@ from ryu.exception import NetworkNotFound, NetworkAlreadyExist
|
|||||||
from ryu.exception import PortAlreadyExist, PortNotFound, PortUnknown
|
from ryu.exception import PortAlreadyExist, PortNotFound, PortUnknown
|
||||||
|
|
||||||
|
|
||||||
LOG = logging.getLogger('ryu.controller.network')
|
|
||||||
|
|
||||||
|
|
||||||
class MacAddressAlreadyExist(ryu_exc.RyuException):
|
class MacAddressAlreadyExist(ryu_exc.RyuException):
|
||||||
message = 'port (%(dpid)s, %(port)s) has already mac %(mac_address)s'
|
message = 'port (%(dpid)s, %(port)s) has already mac %(mac_address)s'
|
||||||
|
|
||||||
@ -434,7 +431,7 @@ class Network(app_manager.RyuApp):
|
|||||||
# allow external network -> known network id
|
# allow external network -> known network id
|
||||||
return True
|
return True
|
||||||
|
|
||||||
LOG.debug('blocked dpid %s nw_id %s out_port %d out_nw %s'
|
self.logger.debug('blocked dpid %s nw_id %s out_port %d out_nw %s'
|
||||||
'external %s',
|
'external %s',
|
||||||
dpid, nw_id, out_port, out_nw, allow_nw_id_external)
|
dpid, nw_id, out_port, out_nw, allow_nw_id_external)
|
||||||
return False
|
return False
|
||||||
|
@ -25,7 +25,6 @@ from ryu.controller.handler import set_ev_handler
|
|||||||
from ryu.controller.handler import HANDSHAKE_DISPATCHER, CONFIG_DISPATCHER,\
|
from ryu.controller.handler import HANDSHAKE_DISPATCHER, CONFIG_DISPATCHER,\
|
||||||
MAIN_DISPATCHER
|
MAIN_DISPATCHER
|
||||||
|
|
||||||
LOG = logging.getLogger('ryu.controller.ofp_handler')
|
|
||||||
|
|
||||||
# The state transition: HANDSHAKE -> CONFIG -> MAIN
|
# The state transition: HANDSHAKE -> CONFIG -> MAIN
|
||||||
#
|
#
|
||||||
@ -46,9 +45,8 @@ class OFPHandler(ryu.base.app_manager.RyuApp):
|
|||||||
super(OFPHandler, self).__init__(*args, **kwargs)
|
super(OFPHandler, self).__init__(*args, **kwargs)
|
||||||
self.name = 'ofp_event'
|
self.name = 'ofp_event'
|
||||||
|
|
||||||
@staticmethod
|
def _hello_failed(self, datapath, error_desc):
|
||||||
def _hello_failed(datapath, error_desc):
|
self.logger.error(error_desc)
|
||||||
LOG.error(error_desc)
|
|
||||||
error_msg = datapath.ofproto_parser.OFPErrorMsg(datapath)
|
error_msg = datapath.ofproto_parser.OFPErrorMsg(datapath)
|
||||||
error_msg.type = datapath.ofproto.OFPET_HELLO_FAILED
|
error_msg.type = datapath.ofproto.OFPET_HELLO_FAILED
|
||||||
error_msg.code = datapath.ofproto.OFPHFC_INCOMPATIBLE
|
error_msg.code = datapath.ofproto.OFPHFC_INCOMPATIBLE
|
||||||
@ -57,7 +55,7 @@ class OFPHandler(ryu.base.app_manager.RyuApp):
|
|||||||
|
|
||||||
@set_ev_handler(ofp_event.EventOFPHello, HANDSHAKE_DISPATCHER)
|
@set_ev_handler(ofp_event.EventOFPHello, HANDSHAKE_DISPATCHER)
|
||||||
def hello_handler(self, ev):
|
def hello_handler(self, ev):
|
||||||
LOG.debug('hello ev %s', ev)
|
self.logger.debug('hello ev %s', ev)
|
||||||
msg = ev.msg
|
msg = ev.msg
|
||||||
datapath = msg.datapath
|
datapath = msg.datapath
|
||||||
|
|
||||||
@ -176,14 +174,14 @@ class OFPHandler(ryu.base.app_manager.RyuApp):
|
|||||||
datapath.send_msg(features_reqeust)
|
datapath.send_msg(features_reqeust)
|
||||||
|
|
||||||
# now move on to config state
|
# now move on to config state
|
||||||
LOG.debug('move onto config mode')
|
self.logger.debug('move onto config mode')
|
||||||
datapath.set_state(CONFIG_DISPATCHER)
|
datapath.set_state(CONFIG_DISPATCHER)
|
||||||
|
|
||||||
@set_ev_handler(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
|
@set_ev_handler(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
|
||||||
def switch_features_handler(self, ev):
|
def switch_features_handler(self, ev):
|
||||||
msg = ev.msg
|
msg = ev.msg
|
||||||
datapath = msg.datapath
|
datapath = msg.datapath
|
||||||
LOG.debug('switch features ev %s', msg)
|
self.logger.debug('switch features ev %s', msg)
|
||||||
|
|
||||||
datapath.id = msg.datapath_id
|
datapath.id = msg.datapath_id
|
||||||
|
|
||||||
@ -202,7 +200,7 @@ class OFPHandler(ryu.base.app_manager.RyuApp):
|
|||||||
)
|
)
|
||||||
datapath.send_msg(set_config)
|
datapath.send_msg(set_config)
|
||||||
|
|
||||||
LOG.debug('move onto main mode')
|
self.logger.debug('move onto main mode')
|
||||||
ev.msg.datapath.set_state(MAIN_DISPATCHER)
|
ev.msg.datapath.set_state(MAIN_DISPATCHER)
|
||||||
|
|
||||||
@set_ev_handler(ofp_event.EventOFPEchoRequest,
|
@set_ev_handler(ofp_event.EventOFPEchoRequest,
|
||||||
@ -219,5 +217,5 @@ class OFPHandler(ryu.base.app_manager.RyuApp):
|
|||||||
[HANDSHAKE_DISPATCHER, CONFIG_DISPATCHER, MAIN_DISPATCHER])
|
[HANDSHAKE_DISPATCHER, CONFIG_DISPATCHER, MAIN_DISPATCHER])
|
||||||
def error_msg_handler(self, ev):
|
def error_msg_handler(self, ev):
|
||||||
msg = ev.msg
|
msg = ev.msg
|
||||||
LOG.debug('error msg ev %s type 0x%x code 0x%x %s',
|
self.logger.debug('error msg ev %s type 0x%x code 0x%x %s',
|
||||||
msg, msg.type, msg.code, utils.hex_array(msg.data))
|
msg, msg.type, msg.code, utils.hex_array(msg.data))
|
||||||
|
Loading…
Reference in New Issue
Block a user