/** IOFConnectionListener */ @Override public void connectionClosed(IOFConnectionBackend connection) { // Disconnect handler's remaining connections cleanup(); // Only remove the switch handler when the main connection is // closed if (connection == this.mainConnection) { switchManager.handshakeDisconnected(connection.getDatapathId()); if(sw != null) { log.debug("[{}] - main connection {} closed - disconnecting switch", connection); setSwitchStatus(SwitchStatus.DISCONNECTED); switchManager.switchDisconnected(sw); } } }
@Override public IOFSwitchBackend getOFSwitchInstance(IOFConnectionBackend connection, SwitchDescription description, OFFactory factory, DatapathId datapathId) { return null; }
public OFSwitch(IOFConnectionBackend connection, @Nonnull OFFactory factory, @Nonnull IOFSwitchManager switchManager, @Nonnull DatapathId datapathId) { if(connection == null) throw new NullPointerException("connection must not be null"); if(!connection.getAuxId().equals(OFAuxId.MAIN)) throw new IllegalArgumentException("connection must be the main connection"); if(factory == null) throw new NullPointerException("factory must not be null"); if(switchManager == null) throw new NullPointerException("switchManager must not be null"); this.connected = true; this.factory = factory; this.switchManager = switchManager; this.datapathId = datapathId; this.attributes = new ConcurrentHashMap<Object, Object>(); this.role = null; this.description = new SwitchDescription(); this.portManager = new PortManager(); this.status = SwitchStatus.HANDSHAKE; // Connections this.connections = new ConcurrentHashMap<OFAuxId, IOFConnectionBackend>(); this.connections.put(connection.getAuxId(), connection); // Switch's controller connection this.controllerConnections = ImmutableMap.of(); // Defaults properties for an ideal switch this.setAttribute(PROP_FASTWILDCARDS, EnumSet.allOf(OFFlowWildcards.class)); this.setAttribute(PROP_SUPPORTS_OFPP_FLOOD, Boolean.TRUE); this.setAttribute(PROP_SUPPORTS_OFPP_TABLE, Boolean.TRUE); this.tableFeaturesByTableId = new HashMap<TableId, TableFeatures>(); this.tables = new ArrayList<TableId>(); this.securityKernel = switchManager.getSecurityKernelService(); }
@Override public void disconnect() { // Iterate through connections and perform cleanup for (Entry<OFAuxId, IOFConnectionBackend> entry : this.connections.entrySet()) { entry.getValue().disconnect(); this.connections.remove(entry.getKey()); } log.debug("~~~~~~~SWITCH DISCONNECTED~~~~~~"); // Remove all counters from the store connected = false; }
/** * Create a new unconnected OFChannelHandler. * @param controller * @param broker * @throws SwitchHandshakeHandlerException */ OFSwitchHandshakeHandler(@Nonnull IOFConnectionBackend connection, @Nonnull OFFeaturesReply featuresReply, @Nonnull IOFSwitchManager switchManager, @Nonnull RoleManager roleManager, @Nonnull Timer timer) { Preconditions.checkNotNull(connection, "connection"); Preconditions.checkNotNull(featuresReply, "featuresReply"); Preconditions.checkNotNull(switchManager, "switchManager"); Preconditions.checkNotNull(roleManager, "roleManager"); Preconditions.checkNotNull(timer, "timer"); Preconditions.checkArgument(connection.getAuxId().equals(OFAuxId.MAIN), "connection must be MAIN connection but is %s", connection); this.switchManager = switchManager; this.roleManager = roleManager; this.mainConnection = connection; this.auxConnections = new ConcurrentHashMap<OFAuxId, IOFConnectionBackend>(); this.featuresReply = featuresReply; this.timer = timer; this.switchManagerCounters = switchManager.getCounters(); this.factory = OFFactories.getFactory(featuresReply.getVersion()); this.roleChanger = new RoleChanger(DEFAULT_ROLE_TIMEOUT_NS); setState(new InitState()); this.pendingPortStatusMsg = new ArrayList<OFPortStatus>(); connection.setListener(this); }
/** * Called by the switch manager when new aux connections have connected. * This alerts the state machine of an aux connection. * * @param connection * the aux connection */ public synchronized void auxConnectionOpened(IOFConnectionBackend connection) { if(log.isDebugEnabled()) log.debug("[{}] - Switch Handshake - new aux connection {}", this.getDpid(), connection.getAuxId()); // Handle new Auxiliary connections if the main connection has completed (i.e. in ACTIVE or STANDBY state) if (this.getState().equals("ACTIVE") || this.getState().equals("STANDBY")) { auxConnections.put(connection.getAuxId(), connection); connection.setListener(OFSwitchHandshakeHandler.this); log.info("Auxiliary connection {} added for {}.", connection.getAuxId().getValue(), connection.getDatapathId().toString()); } else { log.info("Auxiliary connection {} initiated for {} before main connection handshake complete. Ignorning aux connection attempt.", connection.getAuxId().getValue(), connection.getDatapathId().toString()); } }
/** * Determines if this handshake handler is responsible for the supplied * connection. * * @param connection * an OF connection * @return true if the handler has the connection */ public boolean hasConnection(IOFConnectionBackend connection) { if (this.mainConnection.equals(connection) || this.auxConnections.get(connection.getAuxId()) == connection) { return true; } else { return false; } }
void cleanup() { for (IOFConnectionBackend conn : this.auxConnections.values()) { conn.disconnect(); } this.mainConnection.disconnect(); }
@Override public IOFSwitchBackend getOFSwitchInstance(IOFConnectionBackend connection, SwitchDescription description, OFFactory factory, DatapathId datapathId) { return this.driverRegistry.getOFSwitchInstance(connection, description, factory, datapathId); }
public OFSwitch(IOFConnectionBackend connection, @Nonnull OFFactory factory, @Nonnull IOFSwitchManager switchManager, @Nonnull DatapathId datapathId) { if(connection == null) throw new NullPointerException("connection must not be null"); if(!connection.getAuxId().equals(OFAuxId.MAIN)) throw new IllegalArgumentException("connection must be the main connection"); if(factory == null) throw new NullPointerException("factory must not be null"); if(switchManager == null) throw new NullPointerException("switchManager must not be null"); this.connected = true; this.factory = factory; this.switchManager = switchManager; this.datapathId = datapathId; this.attributes = new ConcurrentHashMap<Object, Object>(); this.role = null; this.description = new SwitchDescription(); this.portManager = new PortManager(); this.status = SwitchStatus.HANDSHAKE; // Connections this.connections = new ConcurrentHashMap<OFAuxId, IOFConnectionBackend>(); this.connections.put(connection.getAuxId(), connection); // Switch's controller connection this.controllerConnections = ImmutableMap.of(); // Defaults properties for an ideal switch this.setAttribute(PROP_FASTWILDCARDS, EnumSet.allOf(OFFlowWildcards.class)); this.setAttribute(PROP_SUPPORTS_OFPP_FLOOD, Boolean.TRUE); this.setAttribute(PROP_SUPPORTS_OFPP_TABLE, Boolean.TRUE); this.tableFeaturesByTableId = new HashMap<TableId, TableFeatures>(); this.tables = new ArrayList<TableId>(); }