@Override public synchronized void addSwitchDriver(String manufacturerDescPrefix, IOFSwitchDriver driver) { if (manufacturerDescPrefix == null) { throw new NullPointerException("manufacturerDescrptionPrefix" + " must not be null"); } if (driver == null) { throw new NullPointerException("driver must not be null"); } IOFSwitchDriver existingDriver = switchBindingMap.get(manufacturerDescPrefix); if (existingDriver != null ) { throw new IllegalStateException("Failed to add OFSwitch driver for " + manufacturerDescPrefix + "already registered"); } switchBindingMap.put(manufacturerDescPrefix, driver); switchDescSorted.add(manufacturerDescPrefix); }
@Override public void addOFSwitchDriver(String description, IOFSwitchDriver driver) { IOFSwitchDriver existingDriver = switchBindingMap.get(description); if (existingDriver != null) { log.warn("Failed to add OFSwitch driver for {}, " + "already registered", description); return; } switchBindingMap.put(description, driver); // Sort so we match the longest string first int index = -1; for (String desc : switchDescSortedList) { if (description.compareTo(desc) > 0) { index = switchDescSortedList.indexOf(desc); switchDescSortedList.add(index, description); break; } } if (index == -1) { // append to list switchDescSortedList.add(description); } }
/** * Initialize internal data structures */ public void init(Map<String, String> configParams) { // These data structures are initialized here because other // module's startUp() might be called before ours this.messageListeners = new ConcurrentHashMap<OFType, ListenerDispatcher<OFType, IOFMessageListener>>(); this.switchListeners = new CopyOnWriteArraySet<IOFSwitchListener>(); this.haListeners = new CopyOnWriteArraySet<IHAListener>(); this.switchBindingMap = new ConcurrentHashMap<String, IOFSwitchDriver>(); this.switchDescSortedList = new ArrayList<String>(); this.activeSwitches = new ConcurrentHashMap<Long, IOFSwitch>(); this.connectedSwitches = new HashSet<IOFSwitch>(); this.controllerNodeIPsCache = new HashMap<String, String>(); this.updates = new LinkedBlockingQueue<IUpdate>(); this.factory = new BasicFactory(); this.providerMap = new HashMap<String, List<IInfoProvider>>(); setConfigParams(configParams); this.role = getInitialRole(configParams); this.notifiedRole = this.role; this.roleChanger = new RoleChanger(this); initVendorMessages(); this.systemStartTime = System.currentTimeMillis(); }
@Override public synchronized void addSwitchDriver(@Nonnull String manufacturerDescPrefix, @Nonnull IOFSwitchDriver driver) { Preconditions.checkNotNull(manufacturerDescPrefix, "manufactererDescProfix"); Preconditions.checkNotNull(driver, "driver"); IOFSwitchDriver existingDriver = switchBindingMap.get(manufacturerDescPrefix); if (existingDriver != null ) { throw new IllegalStateException("Failed to add OFSwitch driver for " + manufacturerDescPrefix + "already registered"); } switchBindingMap.put(manufacturerDescPrefix, driver); switchDescSorted.add(manufacturerDescPrefix); }
/** * Test SwitchDriverRegistry * Test fallback to default if no switch driver is registered for a * particular prefix */ @Test public void testSwitchDriverRegistryNoDriver() { IOFSwitchDriver driver = createMock(IOFSwitchDriver.class); IOFSwitch returnedSwitch = null; IOFSwitchBackend mockSwitch = createMock(IOFSwitchBackend.class); switchManager.addOFSwitchDriver("test switch", driver); replay(driver); replay(mockSwitch); SwitchDescription desc = new SwitchDescription("test switch", "version 0.9", "", "", ""); reset(driver); reset(mockSwitch); mockSwitch.setSwitchProperties(desc); expectLastCall().once(); expect(driver.getOFSwitchImpl(desc, factory)).andReturn(mockSwitch).once(); replay(driver); replay(mockSwitch); returnedSwitch = switchManager.getOFSwitchInstance(new NullConnection(), desc, factory, DatapathId.of(1)); assertSame(mockSwitch, returnedSwitch); verify(driver); verify(mockSwitch); desc = new SwitchDescription("Foo Bar test switch", "version 0.9", "", "", ""); reset(driver); reset(mockSwitch); replay(driver); replay(mockSwitch); returnedSwitch = switchManager.getOFSwitchInstance(new NullConnection(), desc, OFFactories.getFactory(OFVersion.OF_10), DatapathId.of(1)); assertNotNull(returnedSwitch); assertTrue("Returned switch should be OFSwitch", returnedSwitch instanceof OFSwitch); assertEquals(desc, returnedSwitch.getSwitchDescription()); verify(driver); verify(mockSwitch); }
/** * Initialize internal data structures */ public void init(Map<String, String> configParams) { // These data structures are initialized here because other // module's startUp() might be called before ours this.messageListeners = new ConcurrentHashMap<OFType, ListenerDispatcher<OFType, IOFMessageListener>>(); this.switchListeners = new CopyOnWriteArraySet<IOFSwitchListener>(); this.haListeners = new CopyOnWriteArraySet<IHAListener>(); this.switchBindingMap = new ConcurrentHashMap<String, IOFSwitchDriver>(); this.switchDescSortedList = new ArrayList<String>(); this.activeSwitches = new ConcurrentHashMap<Long, IOFSwitch>(); this.connectedSwitches = new HashSet<IOFSwitch>(); this.controllerNodeIPsCache = new HashMap<String, String>(); this.updates = new LinkedBlockingQueue<IUpdate>(); this.factory = new BasicFactory(); this.providerMap = new HashMap<String, List<IInfoProvider>>(); setConfigParams(configParams); this.role = getInitialRole(configParams); this.notifiedRole = this.role; this.roleChanger = new RoleChanger(this); initVendorMessages(); String option = configParams.get("flushSwitchesOnReconnect"); if (option != null && option.equalsIgnoreCase("true")) { this.setAlwaysClearFlowsOnSwAdd(true); log.info("Flush switches on reconnect -- Enabled."); } else { this.setAlwaysClearFlowsOnSwAdd(false); log.info("Flush switches on reconnect -- Disabled"); } }
@Override public void addOFSwitchDriver(String manufacturerDescriptionPrefix, IOFSwitchDriver driver) { // do nothing }
public NaiveSwitchDriverRegistry(@Nonnull IOFSwitchManager switchManager) { Preconditions.checkNotNull(switchManager, "switchManager must not be null"); this.switchManager = switchManager; switchBindingMap = new HashMap<String, IOFSwitchDriver>(); switchDescSorted = new TreeSet<String>(Collections.reverseOrder()); }
@Override public void addOFSwitchDriver(String manufacturerDescriptionPrefix, IOFSwitchDriver driver) { this.driverRegistry.addSwitchDriver(manufacturerDescriptionPrefix, driver); }
@Override public void addOFSwitchDriver(String manufacturerDescriptionPrefix, IOFSwitchDriver driver) { driverRegistry.addSwitchDriver(manufacturerDescriptionPrefix, driver); }
public NaiiveSwitchDriverRegistry() { switchBindingMap = new HashMap<String, IOFSwitchDriver>(); switchDescSorted = new TreeSet<String>(Collections.reverseOrder()); }