X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fprotocol_plugins%2Fopenflow%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fprotocol_plugin%2Fopenflow%2Fcore%2Finternal%2FController.java;h=2863070cc5a7a34ff0f2d95475cd5a9359a443f3;hb=06aa5ce746e29a3760688b2ef2817f50bec5ea7a;hp=f183b516de5fb4de0b60a79618664c58108209e1;hpb=0a980f274122e5b73f40dfb9a85783f3023e08a6;p=controller.git diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/Controller.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/Controller.java index f183b516de..2863070cc5 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/Controller.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/Controller.java @@ -1,4 +1,3 @@ - /* * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. * @@ -53,7 +52,8 @@ public class Controller implements IController, CommandProvider { private AtomicInteger switchInstanceNumber; /* - * this thread monitors the switchEvents queue for new incoming events from switch + * this thread monitors the switchEvents queue for new incoming events from + * switch */ private class EventHandler implements Runnable { @Override @@ -64,17 +64,13 @@ public class Controller implements IController, CommandProvider { SwitchEvent ev = switchEvents.take(); SwitchEvent.SwitchEventType eType = ev.getEventType(); ISwitch sw = ev.getSwitch(); - if (eType != SwitchEvent.SwitchEventType.SWITCH_MESSAGE) { - //logger.debug("Received " + ev.toString() + " from " + sw.toString()); - } switch (eType) { case SWITCH_ADD: Long sid = sw.getId(); ISwitch existingSwitch = switches.get(sid); if (existingSwitch != null) { - logger.info(" Replacing existing " - + existingSwitch.toString() + " with New " - + sw.toString()); + logger.info("Replacing existing {} with New {}", + existingSwitch, sw); disconnectSwitch(existingSwitch); } switches.put(sid, sw); @@ -97,7 +93,7 @@ public class Controller implements IController, CommandProvider { } break; default: - logger.error("unknow switch event " + eType.ordinal()); + logger.error("Unknown switch event {}", eType.ordinal()); } } catch (InterruptedException e) { switchEvents.clear(); @@ -111,27 +107,25 @@ public class Controller implements IController, CommandProvider { /** * Function called by the dependency manager when all the required * dependencies are satisfied - * + * */ public void init() { - logger.debug("OpenFlowCore init"); + logger.debug("Initializing!"); this.switches = new ConcurrentHashMap(); this.switchEvents = new LinkedBlockingQueue(); this.messageListeners = new ConcurrentHashMap(); this.switchStateListener = null; this.switchInstanceNumber = new AtomicInteger(0); registerWithOSGIConsole(); - } /** - * Function called by dependency manager after "init ()" is called - * and after the services provided by the class are registered in - * the service registry - * + * Function called by dependency manager after "init ()" is called and after + * the services provided by the class are registered in the service registry + * */ public void start() { - logger.debug("OpenFlowCore start() is called"); + logger.debug("Starting!"); /* * start a thread to handle event coming from the switch */ @@ -143,15 +137,15 @@ public class Controller implements IController, CommandProvider { try { controllerIO.start(); } catch (IOException ex) { - logger.error("Caught exception: " + ex + " during start"); + logger.error("Caught exception while starting:", ex); } } /** - * Function called by the dependency manager before the services - * exported by the component are unregistered, this will be - * followed by a "destroy ()" calls - * + * Function called by the dependency manager before the services exported by + * the component are unregistered, this will be followed by a "destroy ()" + * calls + * */ public void stop() { for (Iterator> it = switches.entrySet().iterator(); it @@ -162,17 +156,17 @@ public class Controller implements IController, CommandProvider { } switchEventThread.interrupt(); try { - controllerIO.shutDown(); + controllerIO.shutDown(); } catch (IOException ex) { - logger.error("Caught exception: " + ex + " during stop"); + logger.error("Caught exception while stopping:", ex); } } /** - * Function called by the dependency manager when at least one - * dependency become unsatisfied or when the component is shutting - * down because for example bundle is being stopped. - * + * Function called by the dependency manager when at least one dependency + * become unsatisfied or when the component is shutting down because for + * example bundle is being stopped. + * */ public void destroy() { } @@ -181,18 +175,18 @@ public class Controller implements IController, CommandProvider { public void addMessageListener(OFType type, IMessageListener listener) { IMessageListener currentListener = this.messageListeners.get(type); if (currentListener != null) { - logger.warn(type.toString() + " already listened by " - + currentListener.toString()); + logger.warn("{} is already listened by {}", type, + currentListener); } this.messageListeners.put(type, listener); - logger.debug(type.toString() + " is now listened by " - + listener.toString()); + logger.debug("{} is now listened by {}", type, listener); } @Override public void removeMessageListener(OFType type, IMessageListener listener) { IMessageListener currentListener = this.messageListeners.get(type); if ((currentListener != null) && (currentListener == listener)) { + logger.debug("{} listener {} is Removed", type, listener); this.messageListeners.remove(type); } } @@ -200,17 +194,18 @@ public class Controller implements IController, CommandProvider { @Override public void addSwitchStateListener(ISwitchStateListener listener) { if (this.switchStateListener != null) { - logger.warn(this.switchStateListener.toString() - + "already listened to switch events"); + logger.warn("Switch events are already listened by {}", + this.switchStateListener); } this.switchStateListener = listener; - logger.debug(listener.toString() + " now listens to switch events"); + logger.debug("Switch events are now listened by {}", listener); } @Override public void removeSwitchStateListener(ISwitchStateListener listener) { if ((this.switchStateListener != null) && (this.switchStateListener == listener)) { + logger.debug("SwitchStateListener {} is Removed", listener); this.switchStateListener = null; } } @@ -228,7 +223,12 @@ public class Controller implements IController, CommandProvider { SwitchHandler switchHandler = new SwitchHandler(this, sc, instanceName); switchHandler.start(); - logger.info(instanceName + " connected: " + sc.toString()); + if (sc.isConnected()) { + logger.info("Switch:{} is connected to the Controller", + sc.socket().getRemoteSocketAddress() + .toString().split("/")[1]); + } + } catch (IOException e) { return; } @@ -238,14 +238,12 @@ public class Controller implements IController, CommandProvider { if (((SwitchHandler) sw).isOperational()) { Long sid = sw.getId(); if (this.switches.remove(sid, sw)) { - logger.warn(sw.toString() + " is disconnected"); + logger.warn("{} is Disconnected", sw); notifySwitchDeleted(sw); - } else { - //logger.warn(sw.toString() + " has been replaced by " + - // this.switches.get(sid)); } } ((SwitchHandler) sw).stop(); + sw = null; } private void notifySwitchAdded(ISwitch sw) { @@ -264,12 +262,11 @@ public class Controller implements IController, CommandProvider { try { this.switchEvents.put(event); } catch (InterruptedException e) { - e.printStackTrace(); - logger.error("Interrupt Exception " + e.toString()); + logger.debug("SwitchEvent caught Interrupt Exception"); } } - public void takeSwtichEventAdd(ISwitch sw) { + public void takeSwitchEventAdd(ISwitch sw) { SwitchEvent ev = new SwitchEvent( SwitchEvent.SwitchEventType.SWITCH_ADD, sw, null); addSwitchEvent(ev); @@ -318,7 +315,8 @@ public class Controller implements IController, CommandProvider { while (iter.hasNext()) { Long sid = iter.next(); Date date = switches.get(sid).getConnectedDate(); - String switchInstanceName = ((SwitchHandler) switches.get(sid)).getInstanceName(); + String switchInstanceName = ((SwitchHandler) switches.get(sid)) + .getInstanceName(); s.append(switchInstanceName + "/" + HexString.toHexString(sid) + " connected since " + date.toString() + "\n"); } @@ -338,6 +336,28 @@ public class Controller implements IController, CommandProvider { } } + public void _controllerShowConnConfig(CommandInterpreter ci) { + String str = System.getProperty("secureChannelEnabled"); + if ((str != null) && (str.trim().equalsIgnoreCase("true"))) { + ci.print("The Controller and Switch should communicate through TLS connetion.\n"); + + String keyStoreFile = System.getProperty("controllerKeyStore"); + String trustStoreFile = System.getProperty("controllerTrustStore"); + if ((keyStoreFile == null) || keyStoreFile.trim().isEmpty()) { + ci.print("controllerKeyStore not specified in ./configuration/config.ini\n"); + } else { + ci.print("controllerKeyStore=" + keyStoreFile + "\n"); + } + if ((trustStoreFile == null) || trustStoreFile.trim().isEmpty()) { + ci.print("controllerTrustStore not specified in ./configuration/config.ini\n"); + } else { + ci.print("controllerTrustStore=" + trustStoreFile + "\n"); + } + } else { + ci.print("The Controller and Switch should communicate through TCP connetion.\n"); + } + } + private void registerWithOSGIConsole() { BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()) .getBundleContext(); @@ -348,9 +368,10 @@ public class Controller implements IController, CommandProvider { @Override public String getHelp() { StringBuffer help = new StringBuffer(); - help.append("--Open Flow Controller --\n"); - help.append("\tcontrollerShowSwitches\n"); - help.append("\tcontrollerReset\n"); + help.append("---Open Flow Controller---\n"); + help.append("\t controllerShowSwitches\n"); + help.append("\t controllerReset\n"); + help.append("\t controllerShowConnConfig\n"); return help.toString(); } }