From 998a8ad543058e48f303f422c4585f148c3ae23d Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Tue, 5 Mar 2013 13:18:05 +0900 Subject: [PATCH] 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 Signed-off-by: FUJITA Tomonori --- ryu/app/gre_tunnel.py | 15 +++----- ryu/app/quantum_adapter.py | 65 ++++++++++++++++---------------- ryu/app/simple_isolation.py | 42 ++++++++++----------- ryu/app/simple_switch.py | 15 ++++---- ryu/app/simple_vlan.py | 43 ++++++++++----------- ryu/app/tunnel_port_updater.py | 68 ++++++++++++++++++---------------- ryu/base/app_manager.py | 1 + ryu/controller/network.py | 9 ++--- ryu/controller/ofp_handler.py | 18 ++++----- 9 files changed, 134 insertions(+), 142 deletions(-) diff --git a/ryu/app/gre_tunnel.py b/ryu/app/gre_tunnel.py index bf43c8bb..29e8cabc 100644 --- a/ryu/app/gre_tunnel.py +++ b/ryu/app/gre_tunnel.py @@ -32,9 +32,6 @@ from ryu.lib import dpid as dpid_lib from ryu.lib import mac -LOG = logging.getLogger(__name__) - - def _is_reserved_port(ofproto, port_no): return port_no > ofproto.OFPP_MAX @@ -249,7 +246,7 @@ class PortSet(app_manager.RyuApp): if not enter_leave: # TODO:XXX # 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 ports = set(port.port_no for port in ev.ports) @@ -928,7 +925,7 @@ class GRETunnel(app_manager.RyuApp): # follows vm port deletion. # the tunnel port is deleted if and only if no instance of same # 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) # SRC_TABLE: TUNNEL-port catch-all drop rule @@ -939,11 +936,11 @@ class GRETunnel(app_manager.RyuApp): @handler.set_ev_handler(PortSet.EventTunnelKeyDel) 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) 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: self._vm_port_add(ev) else: @@ -951,7 +948,7 @@ class GRETunnel(app_manager.RyuApp): @handler.set_ev_handler(PortSet.EventTunnelPort) 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: self._tunnel_port_add(ev) else: @@ -961,6 +958,6 @@ class GRETunnel(app_manager.RyuApp): def packet_in_handler(self, ev): # for debug 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 msg.datapath.send_packet_out(msg.buffer_id, msg.in_port, []) diff --git a/ryu/app/quantum_adapter.py b/ryu/app/quantum_adapter.py index 2113d7e7..46cdd9d7 100644 --- a/ryu/app/quantum_adapter.py +++ b/ryu/app/quantum_adapter.py @@ -40,11 +40,10 @@ from gevent import monkey monkey.patch_all() -LOG = logging.getLogger(__name__) CONF = cfg.CONF -def _get_auth_token(): +def _get_auth_token(logger): httpclient = q_client.HTTPClient( username=CONF.quantum_admin_username, tenant_name=CONF.quantum_admin_tenant_name, @@ -55,9 +54,9 @@ def _get_auth_token(): try: httpclient.authenticate() 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 - # LOG.debug("_get_auth_token: token=%s", httpclient.auth_token) + # logger.debug("_get_auth_token: token=%s", httpclient.auth_token) return httpclient.auth_token @@ -126,16 +125,17 @@ class OVSPort(object): class OVSSwitch(object): - def __init__(self, dpid, nw, ifaces): + def __init__(self, dpid, nw, ifaces, logger): # TODO: clean up token = None if CONF.quantum_auth_strategy: - token = _get_auth_token() + token = _get_auth_token(logger) q_api = _get_quantum_client(token) self.dpid = dpid self.network_api = nw self.ifaces = ifaces + self.logger = logger self.q_api = q_api self.ctrl_addr = CONF.quantum_controller_addr @@ -149,8 +149,8 @@ class OVSSwitch(object): def set_ovsdb_addr(self, dpid, ovsdb_addr): # easy check if the address format valid - LOG.debug('set_ovsdb_addr dpid %s ovsdb_addr %s', - dpid_lib.dpid_to_str(dpid), ovsdb_addr) + self.logger.debug('set_ovsdb_addr dpid %s ovsdb_addr %s', + dpid_lib.dpid_to_str(dpid), ovsdb_addr) _proto, _host, _port = ovsdb_addr.split(':') old_address = self.ovsdb_addr @@ -164,7 +164,7 @@ class OVSSwitch(object): return self.ovsdb_addr = ovsdb_addr 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) self.ovs_bridge = ovs_bridge ovs_bridge.init() @@ -172,7 +172,7 @@ class OVSSwitch(object): # not overwrite controllers, but append this controller ovs_bridge.set_controller([self.ctrl_addr]) 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) def _update_external_port(self, port, add=True): @@ -184,7 +184,7 @@ class OVSSwitch(object): self.dpid, port.ofport) 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') if iface_id is None: return @@ -223,12 +223,12 @@ class OVSSwitch(object): 'deleted': True } body = {'port': port_data} - # LOG.debug("port-body = %s", body) + # self.logger.debug("port-body = %s", body) try: self.q_api.update_port(port.ext_ids['iface-id'], body) 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, # it should get auth token again return @@ -242,7 +242,8 @@ class OVSSwitch(object): mac_lib.haddr_to_bin(mac)) 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 old_port = self.ports.get(port_no) if not add: @@ -256,12 +257,12 @@ class OVSSwitch(object): if 'ofport' not in port_cfg or not port_cfg['ofport']: port_cfg['ofport'] = port_no elif port_cfg['ofport'] != port_no: - LOG.warn('inconsistent port_no: %d port_cfg %s', - port_no, port_cfg) + self.logger.warn('inconsistent port_no: %d port_cfg ' + '%s', port_no, port_cfg) return if port_cfg['name'] != port_name: - LOG.warn('inconsistent port_name: %s port_cfg %s', - port_name, port_cfg) + self.logger.warn('inconsistent port_name: %s ' + 'port_cfg %s', port_name, port_cfg) return new_port.update(port_cfg) @@ -281,10 +282,10 @@ class OVSSwitch(object): if port_type == OVSPort.PORT_ERROR: return 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) else: - # LOG.info("delete port: %s", old_port) + # self.logger.info("delete port: %s", old_port) if port_type != OVSPort.PORT_TUNNEL: self._update_vif_port(old_port, add=False) return @@ -296,17 +297,17 @@ class OVSSwitch(object): if port_type == OVSPort.PORT_ERROR: return 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) else: - # LOG.info("create port: %s", new_port) + # self.logger.info("create port: %s", new_port) if port_type != OVSPort.PORT_TUNNEL: self._update_vif_port(new_port) return if new_port.get_port_type() in (OVSPort.PORT_GUEST, OVSPort.PORT_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) @@ -334,10 +335,10 @@ class QuantumAdapter(app_manager.RyuApp): ovs_switch = self.dps.get(dpid) if not ovs_switch: 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 else: - LOG.debug('ovs switch %s is already known', dpid) + self.logger.debug('ovs switch %s is already known', dpid) return ovs_switch def _port_handler(self, dpid, port_no, port_name, add): @@ -345,8 +346,8 @@ class QuantumAdapter(app_manager.RyuApp): if ovs_switch: ovs_switch.update_port(port_no, port_name, add) else: - LOG.warn('unknown ovs switch %s %s %s %s\n', - dpid, port_no, port_name, add) + self.logger.warn('unknown ovs switch %s %s %s %s\n', + dpid, port_no, port_name, add) @handler.set_ev_cls(dpset.EventDP) def dp_handler(self, ev): @@ -388,24 +389,24 @@ class QuantumAdapter(app_manager.RyuApp): @handler.set_ev_cls(conf_switch.EventConfSwitchSet) 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: self._conf_switch_set_ovsdb_addr(ev.dpid, ev.value) else: - LOG.debug("unknown event: %s", ev) + self.logger.debug("unknown event: %s", ev) @handler.set_ev_cls(conf_switch.EventConfSwitchDel) 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: self._conf_switch_del_ovsdb_addr(ev.dpid) else: - LOG.debug("unknown event: %s", ev) + self.logger.debug("unknown event: %s", ev) @handler.set_ev_cls(quantum_ifaces.EventQuantumIfaceSet) def quantum_iface_set_handler(self, ev): 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 iface_id = ev.iface_id try: diff --git a/ryu/app/simple_isolation.py b/ryu/app/simple_isolation.py index ff8e1e45..1e081091 100644 --- a/ryu/app/simple_isolation.py +++ b/ryu/app/simple_isolation.py @@ -34,9 +34,6 @@ from ryu.lib.mac import haddr_to_str from ryu.lib import mac -LOG = logging.getLogger('ryu.app.simple_isolation') - - class SimpleIsolation(app_manager.RyuApp): _CONTEXTS = { 'network': network.Network, @@ -88,28 +85,29 @@ class SimpleIsolation(app_manager.RyuApp): if not self.nw.same_network(datapath.id, nw_id, out_port, NW_ID_EXTERNAL): - LOG.debug('packet is blocked src %s dst %s ' - 'from %d to %d on datapath %d', - haddr_to_str(src), haddr_to_str(dst), - msg.in_port, out_port, datapath.id) + self.logger.debug('packet is blocked src %s dst %s ' + 'from %d to %d on datapath %d', + haddr_to_str(src), haddr_to_str(dst), + msg.in_port, out_port, datapath.id) return - LOG.debug("learned dpid %s in_port %d out_port %d src %s dst %s", - datapath.id, msg.in_port, out_port, - haddr_to_str(src), haddr_to_str(dst)) + self.logger.debug("learned dpid %s in_port %d out_port " + "%d src %s dst %s", + datapath.id, msg.in_port, out_port, + haddr_to_str(src), haddr_to_str(dst)) actions = [datapath.ofproto_parser.OFPActionOutput(out_port)] self._modflow_and_send_packet(msg, src, dst, actions) def _flood_to_nw_id(self, msg, src, dst, nw_id): datapath = msg.datapath actions = [] - LOG.debug("dpid %s in_port %d src %s dst %s ports %s", - datapath.id, msg.in_port, - haddr_to_str(src), haddr_to_str(dst), - self.nw.dpids.get(datapath.id, {}).items()) + self.logger.debug("dpid %s in_port %d src %s dst %s ports %s", + datapath.id, msg.in_port, + haddr_to_str(src), haddr_to_str(dst), + self.nw.dpids.get(datapath.id, {}).items()) for port_no in self.nw.filter_ports(datapath.id, msg.in_port, 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)) 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) 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 datapath = msg.datapath ofproto = datapath.ofproto @@ -151,9 +149,9 @@ class SimpleIsolation(app_manager.RyuApp): # allow external -> known nw id change self.mac2net.add_mac(src, port_nw_id, NW_ID_EXTERNAL) except MacAddressDuplicated: - LOG.warn('mac address %s is already in use.' - ' So (dpid %s, port %s) can not use it', - haddr_to_str(src), datapath.id, msg.in_port) + self.logger.warn('mac address %s is already in use.' + ' So (dpid %s, port %s) can not use it', + haddr_to_str(src), datapath.id, msg.in_port) # # should we install drop action pro-actively for future? # @@ -241,7 +239,7 @@ class SimpleIsolation(app_manager.RyuApp): out_port) else: # should not occur? - LOG.debug("should this case happen?") + self.logger.debug("should this case happen?") self._drop_packet(msg) elif dst_nw_id == NW_ID_EXTERNAL: # try learned mac @@ -251,7 +249,7 @@ class SimpleIsolation(app_manager.RyuApp): src_nw_id, out_port) else: assert dst_nw_id == NW_ID_UNKNOWN - LOG.debug("Unknown dst_nw_id") + self.logger.debug("Unknown dst_nw_id") self._drop_packet(msg) elif src_nw_id == NW_ID_EXTERNAL: self._modflow_and_drop_packet(msg, src, dst) @@ -263,7 +261,7 @@ class SimpleIsolation(app_manager.RyuApp): # drop packets assert port_nw_id == NW_ID_UNKNOWN self._drop_packet(msg) - # LOG.debug("Unknown port_nw_id") + # self.logger.debug("Unknown port_nw_id") def _port_add(self, ev): # diff --git a/ryu/app/simple_switch.py b/ryu/app/simple_switch.py index 571fceb0..0397bc48 100644 --- a/ryu/app/simple_switch.py +++ b/ryu/app/simple_switch.py @@ -25,8 +25,6 @@ from ryu.ofproto import ofproto_v1_0 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 # independent and dependant parts. @@ -71,8 +69,9 @@ class SimpleSwitch(app_manager.RyuApp): dpid = datapath.id self.mac_to_port.setdefault(dpid, {}) - LOG.info("packet in %s %s %s %s", - dpid, haddr_to_str(src), haddr_to_str(dst), msg.in_port) + self.logger.info("packet in %s %s %s %s", + dpid, haddr_to_str(src), haddr_to_str(dst), + msg.in_port) # learn a mac address to avoid FLOOD next time. self.mac_to_port[dpid][src] = msg.in_port @@ -101,10 +100,10 @@ class SimpleSwitch(app_manager.RyuApp): ofproto = msg.datapath.ofproto 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: - LOG.info("port deleted %s", port_no) + self.logger.info("port deleted %s", port_no) elif reason == ofproto.OFPPR_MODIFY: - LOG.info("port modified %s", port_no) + self.logger.info("port modified %s", port_no) else: - LOG.info("Illeagal port state %s %s", port_no, reason) + self.logger.info("Illeagal port state %s %s", port_no, reason) diff --git a/ryu/app/simple_vlan.py b/ryu/app/simple_vlan.py index 9c7e2454..d92952bd 100644 --- a/ryu/app/simple_vlan.py +++ b/ryu/app/simple_vlan.py @@ -31,9 +31,6 @@ from ryu.lib.ovs import bridge from ryu.ofproto import nx_match -LOG = logging.getLogger(__name__) - - def _is_reserved_port(dp, port_no): return port_no > dp.ofproto.OFPP_MAX @@ -60,8 +57,8 @@ class SimpleVLAN(app_manager.RyuApp): self.tunnels = kwargs['tunnels'] def _port_flow_add(self, dp, port_no): - LOG.debug('ovs_port_update dpid %s port_no %s', - dpid_lib.dpid_to_str(dp.id), port_no) + self.logger.debug('ovs_port_update dpid %s port_no %s', + dpid_lib.dpid_to_str(dp.id), port_no) rule = nx_match.ClsRule() rule.set_in_port(port_no) ofproto = dp.ofproto @@ -72,8 +69,8 @@ class SimpleVLAN(app_manager.RyuApp): priority=self._PRIORITY_NORMAL, actions=actions) def _port_flow_del(self, dp, port_no): - LOG.debug('_port_flow_del dp %s port_no %d', - dpid_lib.dpid_to_str(dp.id), port_no) + self.logger.debug('_port_flow_del dp %s port_no %d', + dpid_lib.dpid_to_str(dp.id), port_no) rule = nx_match.ClsRule() rule.set_in_port(port_no) dp.send_flow_del(rule=rule, cookie=self._COOKIE_NORMAL) @@ -115,18 +112,18 @@ class SimpleVLAN(app_manager.RyuApp): try: port = self.dpset.get_port(dpid, port_no) except ryu_exc.PortNotFound: - LOG.debug('port not found') + self.logger.debug('port not found') return try: ovsdb_addr = self.conf_sw.get_key(dpid, conf_switch_key.OVSDB_ADDR) except KeyError: - LOG.debug('ovsdb_addr not found') + self.logger.debug('ovsdb_addr not found') return 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 # set Port port.name tag=tunnel_key ovs_br = bridge.OVSBridge(dpid, ovsdb_addr, 2) @@ -135,30 +132,30 @@ class SimpleVLAN(app_manager.RyuApp): try: ovs_br.set_db_attribute("Port", port_name, "tag", tunnel_key) except gevent.Timeout: - LOG.error('timout') + self.logger.error('timout') return return True def _port_setup_netid(self, dpid, port_no, network_id): - LOG.debug('_port_setup_netid %s %s %s', - dpid_lib.dpid_to_str(dpid), port_no, network_id) + self.logger.debug('_port_setup_netid %s %s %s', + dpid_lib.dpid_to_str(dpid), port_no, network_id) dp = self.dpset.get(dpid) if dp is None: - LOG.debug('dp not found') + self.logger.debug('dp not found') return if _is_reserved_port(dp, port_no): return 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) return True try: tunnel_key = self.tunnels.get_key(network_id) except tunnels.TunnelKeyNotFound: - LOG.debug('tunnel key not found') + self.logger.debug('tunnel key not found') return return self._port_setup(dp, port_no, tunnel_key) @@ -171,22 +168,22 @@ class SimpleVLAN(app_manager.RyuApp): try: network_id = self.nw.get_network(dpid, port_no) except ryu_exc.PortUnknown: - LOG.debug('port_unknown') + self.logger.debug('port_unknown') self._queue_port_flow_del(dp, port_no) return 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) @handler.set_ev_cls(dpset.EventPortAdd) 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) @handler.set_ev_cls(dpset.EventPortDelete) def port_del_handler(self, ev): - LOG.debug('port_del %s', ev) + self.logger.debug('port_del %s', ev) dp = ev.dp port_no = ev.port.port_no if _is_reserved_port(dp, port_no): @@ -195,14 +192,14 @@ class SimpleVLAN(app_manager.RyuApp): @handler.set_ev_cls(network.EventNetworkPort) def network_port_handler(self, ev): - LOG.debug('network_port %s', ev) + self.logger.debug('network_port %s', ev) if not ev.add_del: return self._port_setup_netid(ev.dpid, ev.port_no, ev.network_id) @handler.set_ev_cls(tunnels.EventTunnelKeyAdd) 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 for (dpid, port_no) in self.nw.list_ports(ev.network_id): dp = self.dpset.get(dpid) @@ -212,7 +209,7 @@ class SimpleVLAN(app_manager.RyuApp): @handler.set_ev_cls(conf_switch.EventConfSwitchSet) 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: return diff --git a/ryu/app/tunnel_port_updater.py b/ryu/app/tunnel_port_updater.py index 6f01ae59..da88b5f8 100644 --- a/ryu/app/tunnel_port_updater.py +++ b/ryu/app/tunnel_port_updater.py @@ -32,7 +32,6 @@ from ryu.lib import dpid as dpid_lib from ryu.lib.ovs import bridge as ovs_bridge -LOG = logging.getLogger(__name__) CONF = cfg.CONF CONF.register_opts([ cfg.StrOpt('tunnel-type', default='gre', @@ -104,11 +103,12 @@ class TunnelPort(object): class TunnelDP(object): 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__() self.dpid = dpid self.network_api = network_api self.tunnel_api = tunnel_api + self.logger = logger self.ovs_bridge = ovs_bridge.OVSBridge(dpid, ovsdb_addr) @@ -127,7 +127,7 @@ class TunnelDP(object): self.ovs_bridge.init() for tp in self.ovs_bridge.get_tunnel_ports(self.tunnel_type): if tp.local_ip != self.tunnel_ip: - LOG.warn('unknown tunnel port %s', tp) + self.logger.warn('unknown tunnel port %s', tp) continue remote_dpid = self.conf_switch.find_dpid(cs_key.OVS_TUNNEL_ADDR, @@ -155,9 +155,9 @@ class TunnelDP(object): return # tunnel ip address is changed. - LOG.warn('local ip address is changed %s: %s -> %s', - dpid_lib.dpid_to_str(remote_dpid), - self.tunnel_ip, remote_ip) + self.logger.warn('local ip address is changed %s: %s -> %s', + dpid_lib.dpid_to_str(remote_dpid), + self.tunnel_ip, remote_ip) # recreate tunnel ports. for tp in list(self.tunnels.values()): if tp.remote_dpid is None: @@ -171,9 +171,9 @@ class TunnelDP(object): return if self.tunnel_ip == remote_ip: - LOG.error('ip conflict: %s %s %s', - dpid_lib.dpid_to_str(self.dpid), - dpid_lib.dpid_to_str(remote_dpid), remote_ip) + self.logger.error('ip conflict: %s %s %s', + dpid_lib.dpid_to_str(self.dpid), + dpid_lib.dpid_to_str(remote_dpid), remote_ip) # XXX What should we do? return @@ -183,9 +183,9 @@ class TunnelDP(object): self._api_update(tp.port_no, remote_dpid) continue - LOG.warn('remote ip address is changed %s: %s -> %s', - dpid_lib.dpid_to_str(remote_dpid), - tp.remote_ip, remote_ip) + self.logger.warn('remote ip address is changed %s: %s -> %s', + dpid_lib.dpid_to_str(remote_dpid), + tp.remote_ip, remote_ip) self._del_tunnel_port(tp.port_no, self.tunnel_ip, tp.remote_ip) new_tp = self._add_tunnel_port(remote_dpid, remote_ip) @@ -215,14 +215,14 @@ class TunnelDP(object): for tp in self.tunnels.values()) def _add_tunnel_port(self, remote_dpid, remote_ip): - LOG.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(remote_dpid), remote_ip) + 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(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 - 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) self.ovs_bridge.add_tunnel_port(port_name, self.tunnel_type, self.tunnel_ip, remote_ip, 'flow') @@ -290,7 +290,7 @@ class TunnelDP(object): try: self._init() except gevent.timeout.Timeout: - LOG.warn('_init timeouted') + self.logger.warn('_init timeouted') req = None while True: @@ -305,19 +305,19 @@ class TunnelDP(object): # shoud use dispatcher? if isinstance(req, self._RequestUpdateRemote): - LOG.debug('update_remote') + self.logger.debug('update_remote') self._update_remote(req.remote_dpid, req.remote_ip) 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) elif isinstance(req, self._RequestDelTunnelPort): - LOG.debug('del_tunnel_port') + self.logger.debug('del_tunnel_port') self._del_tunnel_port_ip(req.remote_ip) else: - LOG.error('unknown request %s', req) + self.logger.error('unknown request %s', req) except gevent.timeout.Timeout: # timeout. try again - LOG.warn('timeout try again') + self.logger.warn('timeout try again') continue else: # Done. move onto next request @@ -369,13 +369,15 @@ class TunnelPortUpdater(app_manager.RyuApp): setattr(self, self._LOCK, gevent.coros.Semaphore()) def _ovsdb_update(self, dpid, ovsdb_addr, ovs_tunnel_addr): - LOG.debug('_ovsdb_update %s %s %s', - dpid_lib.dpid_to_str(dpid), ovsdb_addr, ovs_tunnel_addr) + self.logger.debug('_ovsdb_update %s %s %s', + dpid_lib.dpid_to_str(dpid), ovsdb_addr, + ovs_tunnel_addr) if dpid not in self.tunnel_dpset: # TODO:XXX changing ovsdb_addr, ovs_tunnel_addr tunnel_dp = TunnelDP(dpid, ovsdb_addr, ovs_tunnel_addr, 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 tunnel_dp = self.tunnel_dpset.get(dpid) @@ -385,8 +387,8 @@ class TunnelPortUpdater(app_manager.RyuApp): @handler.set_ev_cls(conf_switch.EventConfSwitchSet) def conf_switch_set_handler(self, ev): - LOG.debug('conf_switch_set_handler %s %s %s', - dpid_lib.dpid_to_str(ev.dpid), ev.key, ev.value) + self.logger.debug('conf_switch_set_handler %s %s %s', + dpid_lib.dpid_to_str(ev.dpid), ev.key, ev.value) dpid = ev.dpid if (ev.key == cs_key.OVSDB_ADDR or ev.key == cs_key.OVS_TUNNEL_ADDR): if ((dpid, cs_key.OVSDB_ADDR) in self.cs and @@ -405,7 +407,7 @@ class TunnelPortUpdater(app_manager.RyuApp): pass 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: remote_dp = self.tunnel_dpset.get(remote_dpid) if remote_dp is None: @@ -416,7 +418,8 @@ class TunnelPortUpdater(app_manager.RyuApp): tunnel_dp.tunnel_ip) 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.remove(dpid) for remote_dpid in dpids: @@ -428,7 +431,8 @@ class TunnelPortUpdater(app_manager.RyuApp): self._add_tunnel_ports(tunnel_dp, dpids) 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: return @@ -459,7 +463,7 @@ class TunnelPortUpdater(app_manager.RyuApp): @handler.set_ev_cls(network.EventNetworkPort) 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: return diff --git a/ryu/base/app_manager.py b/ryu/base/app_manager.py index f20b87cc..a3abc85f 100644 --- a/ryu/base/app_manager.py +++ b/ryu/base/app_manager.py @@ -63,6 +63,7 @@ class RyuApp(object): self.threads = [] self.events = Queue() self.replies = Queue() + self.logger = logging.getLogger(self.name) self.threads.append(gevent.spawn(self._event_loop)) def register_handler(self, ev_cls, handler): diff --git a/ryu/controller/network.py b/ryu/controller/network.py index e576eb56..a3441a8f 100644 --- a/ryu/controller/network.py +++ b/ryu/controller/network.py @@ -25,9 +25,6 @@ from ryu.exception import NetworkNotFound, NetworkAlreadyExist from ryu.exception import PortAlreadyExist, PortNotFound, PortUnknown -LOG = logging.getLogger('ryu.controller.network') - - class MacAddressAlreadyExist(ryu_exc.RyuException): message = 'port (%(dpid)s, %(port)s) has already mac %(mac_address)s' @@ -434,9 +431,9 @@ class Network(app_manager.RyuApp): # allow external network -> known network id return True - LOG.debug('blocked dpid %s nw_id %s out_port %d out_nw %s' - 'external %s', - dpid, nw_id, out_port, out_nw, allow_nw_id_external) + self.logger.debug('blocked dpid %s nw_id %s out_port %d out_nw %s' + 'external %s', + dpid, nw_id, out_port, out_nw, allow_nw_id_external) return False def get_network(self, dpid, port): diff --git a/ryu/controller/ofp_handler.py b/ryu/controller/ofp_handler.py index 2ac72514..84e4d740 100644 --- a/ryu/controller/ofp_handler.py +++ b/ryu/controller/ofp_handler.py @@ -25,7 +25,6 @@ from ryu.controller.handler import set_ev_handler from ryu.controller.handler import HANDSHAKE_DISPATCHER, CONFIG_DISPATCHER,\ MAIN_DISPATCHER -LOG = logging.getLogger('ryu.controller.ofp_handler') # The state transition: HANDSHAKE -> CONFIG -> MAIN # @@ -46,9 +45,8 @@ class OFPHandler(ryu.base.app_manager.RyuApp): super(OFPHandler, self).__init__(*args, **kwargs) self.name = 'ofp_event' - @staticmethod - def _hello_failed(datapath, error_desc): - LOG.error(error_desc) + def _hello_failed(self, datapath, error_desc): + self.logger.error(error_desc) error_msg = datapath.ofproto_parser.OFPErrorMsg(datapath) error_msg.type = datapath.ofproto.OFPET_HELLO_FAILED 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) def hello_handler(self, ev): - LOG.debug('hello ev %s', ev) + self.logger.debug('hello ev %s', ev) msg = ev.msg datapath = msg.datapath @@ -176,14 +174,14 @@ class OFPHandler(ryu.base.app_manager.RyuApp): datapath.send_msg(features_reqeust) # now move on to config state - LOG.debug('move onto config mode') + self.logger.debug('move onto config mode') datapath.set_state(CONFIG_DISPATCHER) @set_ev_handler(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER) def switch_features_handler(self, ev): msg = ev.msg datapath = msg.datapath - LOG.debug('switch features ev %s', msg) + self.logger.debug('switch features ev %s', msg) datapath.id = msg.datapath_id @@ -202,7 +200,7 @@ class OFPHandler(ryu.base.app_manager.RyuApp): ) 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) @set_ev_handler(ofp_event.EventOFPEchoRequest, @@ -219,5 +217,5 @@ class OFPHandler(ryu.base.app_manager.RyuApp): [HANDSHAKE_DISPATCHER, CONFIG_DISPATCHER, MAIN_DISPATCHER]) def error_msg_handler(self, ev): msg = ev.msg - LOG.debug('error msg ev %s type 0x%x code 0x%x %s', - msg, msg.type, msg.code, utils.hex_array(msg.data)) + self.logger.debug('error msg ev %s type 0x%x code 0x%x %s', + msg, msg.type, msg.code, utils.hex_array(msg.data))