Java 类net.floodlightcontroller.core.SwitchDescription 实例源码

项目:open-kilda    文件:PathVerificationFlowTest.java   
@Before
public void setUp() throws Exception {
    logger = LoggerFactory.getLogger(PathVerificationFlowTest.class);
    cntx = new FloodlightContext();
    FloodlightModuleContext fmc = new FloodlightModuleContext();
    fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider);

    swDescription = factory.buildDescStatsReply().build();
    swFeatures = factory.buildFeaturesReply().setNBuffers(1000).build();

    sw = EasyMock.createMock(IOFSwitch.class);
    expect(sw.getId()).andReturn(swDpid).anyTimes();
    expect(sw.getOFFactory()).andReturn(factory).anyTimes();
    expect(sw.getBuffers()).andReturn(swFeatures.getNBuffers()).anyTimes();
    expect(sw.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_TABLE)).andReturn(true).anyTimes();
    expect(sw.getSwitchDescription()).andReturn(new SwitchDescription(swDescription)).anyTimes();
    expect(sw.isActive()).andReturn(true).anyTimes();
    expect(sw.getLatency()).andReturn(U64.of(10L)).anyTimes();
    replay(sw);

    pvs = new PathVerificationService();
}
项目:fresco_floodlight    文件:OFSwitchManagerTest.java   
/**
 * Create and activate a switch, either completely new or reconnected
 * The mocked switch instance will be returned. It will be reset.
 */
private IOFSwitchBackend doActivateSwitchInt(DatapathId datapathId,
                                      SwitchDescription description,
                                      OFFeaturesReply featuresReply,
                                      boolean clearFlows)
                                      throws Exception {

    IOFSwitchBackend sw = createMock(IOFSwitchBackend.class);
    if (featuresReply == null) {
        featuresReply = createOFFeaturesReply(datapathId);
    }
    if (description == null) {
        description = createSwitchDescription();
    }
    setupSwitchForAddSwitch(sw, datapathId, description, featuresReply);
    replay(sw);
    switchManager.switchAdded(sw);
    switchManager.switchStatusChanged(sw, SwitchStatus.HANDSHAKE, SwitchStatus.MASTER);
    verify(sw);
    assertEquals(sw, switchManager.getSwitch(datapathId));
    // drain updates and ignore
    controller.processUpdateQueueForTesting();

    reset(sw);
    return sw;
}
项目:iTAP-controller    文件:OFSwitchManagerTest.java   
/**
 * Create and activate a switch, either completely new or reconnected
 * The mocked switch instance will be returned. It will be reset.
 */
private IOFSwitchBackend doActivateSwitchInt(DatapathId datapathId,
                                      SwitchDescription description,
                                      OFFeaturesReply featuresReply,
                                      boolean clearFlows)
                                      throws Exception {

    IOFSwitchBackend sw = createMock(IOFSwitchBackend.class);
    if (featuresReply == null) {
        featuresReply = createOFFeaturesReply(datapathId);
    }
    if (description == null) {
        description = createSwitchDescription();
    }
    setupSwitchForAddSwitch(sw, datapathId, description, featuresReply);
    replay(sw);
    switchManager.switchAdded(sw);
    switchManager.switchStatusChanged(sw, SwitchStatus.HANDSHAKE, SwitchStatus.MASTER);
    verify(sw);
    assertEquals(sw, switchManager.getSwitch(datapathId));
    // drain updates and ignore
    controller.processUpdateQueueForTesting();

    reset(sw);
    return sw;
}
项目:SDN-Multicast    文件:OFSwitchManagerTest.java   
/**
 * Create and activate a switch, either completely new or reconnected
 * The mocked switch instance will be returned. It will be reset.
 */
private IOFSwitchBackend doActivateSwitchInt(DatapathId datapathId,
                                      SwitchDescription description,
                                      OFFeaturesReply featuresReply,
                                      boolean clearFlows)
                                      throws Exception {

    IOFSwitchBackend sw = createMock(IOFSwitchBackend.class);
    if (featuresReply == null) {
        featuresReply = createOFFeaturesReply(datapathId);
    }
    if (description == null) {
        description = createSwitchDescription();
    }
    setupSwitchForAddSwitch(sw, datapathId, description, featuresReply);
    replay(sw);
    switchManager.switchAdded(sw);
    switchManager.switchStatusChanged(sw, SwitchStatus.HANDSHAKE, SwitchStatus.MASTER);
    verify(sw);
    assertEquals(sw, switchManager.getSwitch(datapathId));
    // drain updates and ignore
    controller.processUpdateQueueForTesting();

    reset(sw);
    return sw;
}
项目:arscheduler    文件:OFSwitchManagerTest.java   
/**
 * Create and activate a switch, either completely new or reconnected
 * The mocked switch instance will be returned. It will be reset.
 */
private IOFSwitchBackend doActivateSwitchInt(DatapathId datapathId,
                                      SwitchDescription description,
                                      OFFeaturesReply featuresReply,
                                      boolean clearFlows)
                                      throws Exception {

    IOFSwitchBackend sw = createMock(IOFSwitchBackend.class);
    if (featuresReply == null) {
        featuresReply = createOFFeaturesReply(datapathId);
    }
    if (description == null) {
        description = createSwitchDescription();
    }
    setupSwitchForAddSwitch(sw, datapathId, description, featuresReply);
    replay(sw);
    switchManager.switchAdded(sw);
    switchManager.switchStatusChanged(sw, SwitchStatus.HANDSHAKE, SwitchStatus.MASTER);
    verify(sw);
    assertEquals(sw, switchManager.getSwitch(datapathId));
    // drain updates and ignore
    controller.processUpdateQueueForTesting();

    reset(sw);
    return sw;
}
项目:floodlight1.2-delay    文件:OFSwitchManagerTest.java   
/**
 * Create and activate a switch, either completely new or reconnected
 * The mocked switch instance will be returned. It will be reset.
 */
private IOFSwitchBackend doActivateSwitchInt(DatapathId datapathId,
                                      SwitchDescription description,
                                      OFFeaturesReply featuresReply,
                                      boolean clearFlows)
                                      throws Exception {

    IOFSwitchBackend sw = createMock(IOFSwitchBackend.class);
    if (featuresReply == null) {
        featuresReply = createOFFeaturesReply(datapathId);
    }
    if (description == null) {
        description = createSwitchDescription();
    }
    setupSwitchForAddSwitch(sw, datapathId, description, featuresReply);
    replay(sw);
    switchManager.switchAdded(sw);
    switchManager.switchStatusChanged(sw, SwitchStatus.HANDSHAKE, SwitchStatus.MASTER);
    verify(sw);
    assertEquals(sw, switchManager.getSwitch(datapathId));
    // drain updates and ignore
    controller.processUpdateQueueForTesting();

    reset(sw);
    return sw;
}
项目:floodlight-hardware    文件:OFSwitchManagerTest.java   
/**
 * Create and activate a switch, either completely new or reconnected
 * The mocked switch instance will be returned. It will be reset.
 */
private IOFSwitchBackend doActivateSwitchInt(DatapathId datapathId,
                                      SwitchDescription description,
                                      OFFeaturesReply featuresReply,
                                      boolean clearFlows)
                                      throws Exception {

    IOFSwitchBackend sw = createMock(IOFSwitchBackend.class);
    if (featuresReply == null) {
        featuresReply = createOFFeaturesReply(datapathId);
    }
    if (description == null) {
        description = createSwitchDescription();
    }
    setupSwitchForAddSwitch(sw, datapathId, description, featuresReply);
    replay(sw);
    switchManager.switchAdded(sw);
    switchManager.switchStatusChanged(sw, SwitchStatus.HANDSHAKE, SwitchStatus.MASTER);
    verify(sw);
    assertEquals(sw, switchManager.getSwitch(datapathId));
    // drain updates and ignore
    controller.processUpdateQueueForTesting();

    reset(sw);
    return sw;
}
项目:open-kilda    文件:SwitchManagerTest.java   
@Before
public void setUp() throws FloodlightModuleException {
    ofSwitchService = createMock(IOFSwitchService.class);
    restApiService = createMock(IRestApiService.class);
    iofSwitch = createMock(IOFSwitch.class);
    switchDescription = createMock(SwitchDescription.class);
    dpid = createMock(DatapathId.class);

    context.addService(IRestApiService.class, restApiService);
    context.addService(IOFSwitchService.class, ofSwitchService);

    switchManager = new SwitchManager();
    switchManager.init(context);
}
项目:open-kilda    文件:FloodlightTestCase.java   
public IOFSwitch buildMockIOFSwitch(Long id, OFPortDesc portDesc, OFFactory factory,
        OFDescStatsReply swDesc, InetSocketAddress inetAddr) {
    IOFSwitch sw = EasyMock.createMock(IOFSwitch.class);
    expect(sw.getId()).andReturn(DatapathId.of(id)).anyTimes();
    expect(sw.getPort(OFPort.of(1))).andReturn(portDesc).anyTimes();
    expect(sw.getOFFactory()).andReturn(factory).anyTimes();
    expect(sw.getBuffers()).andReturn(swFeatures.getNBuffers()).anyTimes();
    expect(sw.hasAttribute(IOFSwitch.PROP_SUPPORTS_OFPP_TABLE)).andReturn(true).anyTimes();
    expect(sw.getSwitchDescription()).andReturn(new SwitchDescription(swDesc)).anyTimes();
    expect(sw.isActive()).andReturn(true).anyTimes();
    expect(sw.getLatency()).andReturn(U64.of(10L)).anyTimes();
    expect(sw.getInetAddress()).andReturn(inetAddr).anyTimes();
    return sw;
}
项目:open-kilda    文件:MockSwitchManager.java   
@Override
public IOFSwitchBackend
        getOFSwitchInstance(IOFConnectionBackend connection,
                            SwitchDescription description,
                            OFFactory factory, DatapathId datapathId) {
    return null;
}
项目:fresco_floodlight    文件:IOFSwitchSerializer.java   
public void serializeDescription(SwitchDescription swDescription, JsonGenerator jGen)
        throws IOException, JsonProcessingException {
    if( null == swDescription)
        jGen.writeStringField("description","null");
    else{
        jGen.writeFieldName("description");
        jGen.writeStartObject();
        jGen.writeStringField("datapath",swDescription.getDatapathDescription());
        jGen.writeStringField("hardware",swDescription.getHardwareDescription());
        jGen.writeStringField("manufacturer",swDescription.getManufacturerDescription());
        jGen.writeStringField("serialNum",swDescription.getSerialNumber());
        jGen.writeStringField("software",swDescription.getSoftwareDescription());
        jGen.writeEndObject();
    }
}
项目:fresco_floodlight    文件:SwitchSyncRepresentation.java   
public SwitchSyncRepresentation(IOFSwitch sw) {
    this.dpid = sw.getId();
    this.buffers = sw.getBuffers();
    this.tables = (short) sw.getNumTables();
    this.capabilities = sw.getCapabilities();
    this.actions = sw.getActions();
    this.ports = toSyncedPortList(sw.getPorts());

    SwitchDescription d = sw.getSwitchDescription();
    this.manufacturerDescription = d.getManufacturerDescription();
    this.hardwareDescription = d.getHardwareDescription();
    this.softwareDescription = d.getSoftwareDescription();
    this.serialNumber = d.getSerialNumber();
    this.datapathDescription = d.getDatapathDescription();
}
项目:fresco_floodlight    文件:SwitchSyncRepresentation.java   
public SwitchSyncRepresentation(OFFeaturesReply fr,
                                SwitchDescription d) {
    this.dpid = fr.getDatapathId();
    this.buffers = fr.getNBuffers();
    this.tables = fr.getNTables();
    this.capabilities = fr.getCapabilities();
    this.actions = fr.getActions();
    this.ports = toSyncedPortList(fr.getPorts());

    this.manufacturerDescription = d.getManufacturerDescription();
    this.hardwareDescription = d.getHardwareDescription();
    this.softwareDescription = d.getSoftwareDescription();
    this.serialNumber = d.getSerialNumber();
    this.datapathDescription = d.getDatapathDescription();
}
项目:fresco_floodlight    文件:OFSwitch.java   
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();

}
项目:fresco_floodlight    文件:OFSwitchHandshakeHandler.java   
@Override
void processOFStatsReply(OFStatsReply m) {
    // Read description, if it has been updated
    if (m.getStatsType() != OFStatsType.DESC) {
        illegalMessageReceived(m);
        return;
    }

    OFDescStatsReply descStatsReply = (OFDescStatsReply) m;
    SwitchDescription description = new SwitchDescription(descStatsReply);
    sw = switchManager.getOFSwitchInstance(mainConnection, description, factory, featuresReply.getDatapathId());

    // set switch information
    // set features reply and channel first so we a DPID and
    // channel info.
    sw.setFeaturesReply(featuresReply);
    if (portDescStats != null) {
        sw.setPortDescStats(portDescStats);
    }

    /*
     * Need to add after setting the features.
     */
    switchManager.switchAdded(sw);

    // Handle pending messages now that we have a sw object
    handlePendingPortStatusMessages(description);

    setState(new WaitTableFeaturesReplyState());
}
项目:fresco_floodlight    文件:OFSwitchHandshakeHandler.java   
void handlePendingPortStatusMessages(SwitchDescription description){
    for (OFPortStatus ps: pendingPortStatusMsg) {
        handlePortStatusMessage(ps, false);
    }
    pendingPortStatusMsg.clear();
    log.info("Switch {} bound to class {}, description {}", new Object[] { sw, sw.getClass(), description });
}
项目:fresco_floodlight    文件:OFSwitchManager.java   
@Override
public IOFSwitchBackend getOFSwitchInstance(IOFConnectionBackend connection,
        SwitchDescription description,
        OFFactory factory, DatapathId datapathId) {

    return this.driverRegistry.getOFSwitchInstance(connection, description, factory, datapathId);
}
项目:fresco_floodlight    文件:OFSwitchManagerTest.java   
/** Set the mock expectations for sw when sw is passed to addSwitch
 * The same expectations can be used when a new SwitchSyncRepresentation
 * is created from the given mocked switch */
protected void setupSwitchForAddSwitch(IOFSwitch sw, DatapathId datapathId,
        SwitchDescription description, OFFeaturesReply featuresReply) {
    if (description == null) {
        description = createSwitchDescription();
    }
    if (featuresReply == null) {
        featuresReply = createOFFeaturesReply(datapathId);
    }
    List<OFPortDesc> ports = featuresReply.getPorts();

    expect(sw.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_10)).anyTimes();
    expect(sw.getStatus()).andReturn(SwitchStatus.MASTER).anyTimes();
    expect(sw.getId()).andReturn(datapathId).anyTimes();
    expect(sw.getSwitchDescription()).andReturn(description).anyTimes();
    expect(sw.getBuffers())
            .andReturn(featuresReply.getNBuffers()).anyTimes();
    expect(sw.getNumTables())
            .andReturn(featuresReply.getNTables()).anyTimes();
    expect(sw.getCapabilities())
            .andReturn(featuresReply.getCapabilities()).anyTimes();
    expect(sw.getActions())
            .andReturn(featuresReply.getActions()).anyTimes();
    expect(sw.getPorts())
            .andReturn(ports).anyTimes();
    expect(sw.attributeEquals(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE, true))
            .andReturn(false).anyTimes();
    expect(sw.getInetAddress()).andReturn(null).anyTimes();
}
项目:fresco_floodlight    文件:OFSwitchManagerTest.java   
/**
 * Create and activate a new switch with the given dpid, features reply
 * and description. If description and/or features reply are null we'll
 * allocate the default one
 * The mocked switch instance will be returned. It wil be reset.
 */
private IOFSwitchBackend doActivateNewSwitch(DatapathId dpid,
                                      SwitchDescription description,
                                      OFFeaturesReply featuresReply)
                                      throws Exception {
    return doActivateSwitchInt(dpid, description, featuresReply, true);
}
项目:fresco_floodlight    文件:OFSwitchHandshakeHandlerVer13Test.java   
public void handleDescStatsAndCreateSwitch() throws Exception {
    // build the stats reply
    OFDescStatsReply sr = createDescriptionStatsReply();

    reset(sw);
    SwitchDescription switchDescription = new SwitchDescription(sr);
    setupSwitchForInstantiationWithReset();
    sw.setPortDescStats(anyObject(OFPortDescStatsReply.class));
    expectLastCall().once();

    expect(sw.getOFFactory()).andReturn(factory).once();
    replay(sw);

    reset(switchManager);
    expect(switchManager.getHandshakePlugins()).andReturn(plugins).anyTimes();
    expect(
           switchManager.getOFSwitchInstance(anyObject(OFConnection.class),
                                          eq(switchDescription),
                                          anyObject(OFFactory.class),
                                          anyObject(DatapathId.class))).andReturn(sw).once();
    expect(switchManager.getNumRequiredConnections()).andReturn(1).anyTimes(); 
    switchManager.switchAdded(sw);
    expectLastCall().once();
    replay(switchManager);

    // send the description stats reply
    switchHandler.processOFMessage(sr);

    OFMessage msg = connection.retrieveMessage();
    assertThat(msg, CoreMatchers.instanceOf(OFTableFeaturesStatsRequest.class));
    verifyUniqueXids(msg);

    verify(sw, switchManager);
}
项目:fresco_floodlight    文件:ControllerTest.java   
/** Set the mock expectations for sw when sw is passed to addSwitch
 * The same expectations can be used when a new SwitchSyncRepresentation
 * is created from the given mocked switch */
protected void setupSwitchForAddSwitch(IOFSwitch sw, DatapathId datapathId,
                                       SwitchDescription description,
                                       OFFeaturesReply featuresReply) {
    String dpidString = datapathId.toString();
    if (description == null) {
        description = createSwitchDescription();
    }
    if (featuresReply == null) {
        featuresReply = createOFFeaturesReply(datapathId);
    }
    List<OFPortDesc> ports = featuresReply.getPorts();

    expect(sw.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_10)).anyTimes();
    expect(sw.getId()).andReturn(datapathId).anyTimes();
    expect(sw.getId().toString()).andReturn(dpidString).anyTimes();
    expect(sw.getSwitchDescription()).andReturn(description).atLeastOnce();
    expect(sw.getBuffers())
            .andReturn(featuresReply.getNBuffers()).atLeastOnce();
    expect(sw.getNumTables())
            .andReturn(featuresReply.getNTables()).atLeastOnce();
    expect(sw.getCapabilities())
            .andReturn(featuresReply.getCapabilities()).atLeastOnce();
    expect(sw.getActions())
            .andReturn(featuresReply.getActions()).atLeastOnce();
    expect(sw.getPorts())
            .andReturn(ports).atLeastOnce();
    expect(sw.attributeEquals(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE, true))
            .andReturn(false).anyTimes();
    expect(sw.getInetAddress()).andReturn(null).anyTimes();
}
项目:fresco_floodlight    文件:OFSwitchHandshakeHandlerVer10Test.java   
public void handleDescStatsAndCreateSwitch(boolean switchDriverComplete) throws Exception {
    // build the stats reply
    OFDescStatsReply sr = createDescriptionStatsReply();

    reset(sw);
    SwitchDescription switchDescription = new SwitchDescription(sr);
    setupSwitchForInstantiationWithReset();
    sw.startDriverHandshake();
    expectLastCall().once();
    expect(sw.getOFFactory()).andReturn(factory).once();
    sw.isDriverHandshakeComplete();
    expectLastCall().andReturn(switchDriverComplete).once();

    if(factory.getVersion().compareTo(OFVersion.OF_13) >= 0) {
        sw.setPortDescStats(anyObject(OFPortDescStatsReply.class));
        expectLastCall().once();
    }

    replay(sw);

    reset(switchManager);
    expect(switchManager.getHandshakePlugins()).andReturn(plugins).anyTimes();
    expect(
           switchManager.getOFSwitchInstance(anyObject(OFConnection.class),
                                          eq(switchDescription),
                                          anyObject(OFFactory.class),
                                          anyObject(DatapathId.class))).andReturn(sw).once();
    switchManager.switchAdded(sw);
    expectLastCall().once();
    replay(switchManager);

    // send the description stats reply
    switchHandler.processOFMessage(sr);
}
项目:fresco_floodlight    文件:MockSwitchManager.java   
@Override
public IOFSwitchBackend
        getOFSwitchInstance(IOFConnectionBackend connection,
                            SwitchDescription description,
                            OFFactory factory, DatapathId datapathId) {
    return null;
}
项目:iTAP-controller    文件:IOFSwitchSerializer.java   
public void serializeDescription(SwitchDescription swDescription, JsonGenerator jGen)
        throws IOException, JsonProcessingException {
    if( null == swDescription)
        jGen.writeStringField("description","null");
    else{
        jGen.writeFieldName("description");
        jGen.writeStartObject();
        jGen.writeStringField("datapath",swDescription.getDatapathDescription());
        jGen.writeStringField("hardware",swDescription.getHardwareDescription());
        jGen.writeStringField("manufacturer",swDescription.getManufacturerDescription());
        jGen.writeStringField("serialNum",swDescription.getSerialNumber());
        jGen.writeStringField("software",swDescription.getSoftwareDescription());
        jGen.writeEndObject();
    }
}
项目:iTAP-controller    文件:SwitchSyncRepresentation.java   
public SwitchSyncRepresentation(IOFSwitch sw) {
    this.dpid = sw.getId();
    this.buffers = sw.getBuffers();
    this.tables = sw.getTables();
    this.capabilities = sw.getCapabilities();
    this.actions = sw.getActions();
    this.ports = toSyncedPortList(sw.getPorts());

    SwitchDescription d = sw.getSwitchDescription();
    this.manufacturerDescription = d.getManufacturerDescription();
    this.hardwareDescription = d.getHardwareDescription();
    this.softwareDescription = d.getSoftwareDescription();
    this.serialNumber = d.getSerialNumber();
    this.datapathDescription = d.getDatapathDescription();
}
项目:iTAP-controller    文件:SwitchSyncRepresentation.java   
public SwitchSyncRepresentation(OFFeaturesReply fr,
                                SwitchDescription d) {
    this.dpid = fr.getDatapathId();
    this.buffers = fr.getNBuffers();
    this.tables = fr.getNTables();
    this.capabilities = fr.getCapabilities();
    this.actions = fr.getActions();
    this.ports = toSyncedPortList(fr.getPorts());

    this.manufacturerDescription = d.getManufacturerDescription();
    this.hardwareDescription = d.getHardwareDescription();
    this.softwareDescription = d.getSoftwareDescription();
    this.serialNumber = d.getSerialNumber();
    this.datapathDescription = d.getDatapathDescription();
}
项目:iTAP-controller    文件:OFSwitchHandshakeHandler.java   
@LogMessageDoc(message="Switch {switch info} bound to class " +
        "{switch driver}, description {switch description}",
        explanation="The specified switch has been bound to " +
                "a switch driver based on the switch description" +
        "received from the switch")
@Override
void processOFStatsReply(OFStatsReply m) {
    // Read description, if it has been updated
    if (m.getStatsType() != OFStatsType.DESC) {
        illegalMessageReceived(m);
        return;
    }

    OFDescStatsReply descStatsReply = (OFDescStatsReply) m;
    SwitchDescription description = new SwitchDescription(descStatsReply);
    sw = switchManager.getOFSwitchInstance(mainConnection, description, factory, featuresReply.getDatapathId());
    switchManager.switchAdded(sw);
    // set switch information
    // set features reply and channel first so we a DPID and
    // channel info.
    sw.setFeaturesReply(featuresReply);
    if (portDescStats != null) {
        sw.setPortDescStats(portDescStats);
    }

    // Handle pending messages now that we have a sw object
    handlePendingPortStatusMessages(description);

    sw.startDriverHandshake();
    if (sw.isDriverHandshakeComplete()) {
        setState(new WaitAppHandshakeState());
    } else {
        setState(new WaitSwitchDriverSubHandshakeState());
    }
}
项目:iTAP-controller    文件:OFSwitchHandshakeHandler.java   
void handlePendingPortStatusMessages(SwitchDescription description){
    for (OFPortStatus ps: pendingPortStatusMsg) {
        handlePortStatusMessage(ps, false);
    }
    pendingPortStatusMsg.clear();
    log.info("Switch {} bound to class {}, description {}", new Object[] { sw, sw.getClass(), description });
}
项目:iTAP-controller    文件:OFSwitchManagerTest.java   
/** Set the mock expectations for sw when sw is passed to addSwitch
 * The same expectations can be used when a new SwitchSyncRepresentation
 * is created from the given mocked switch */
protected void setupSwitchForAddSwitch(IOFSwitch sw, DatapathId datapathId,
        SwitchDescription description, OFFeaturesReply featuresReply) {
    if (description == null) {
        description = createSwitchDescription();
    }
    if (featuresReply == null) {
        featuresReply = createOFFeaturesReply(datapathId);
    }
    List<OFPortDesc> ports = featuresReply.getPorts();

    expect(sw.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_10)).anyTimes();
    expect(sw.getStatus()).andReturn(SwitchStatus.MASTER).anyTimes();
    expect(sw.getId()).andReturn(datapathId).anyTimes();
    expect(sw.getSwitchDescription()).andReturn(description).anyTimes();
    expect(sw.getBuffers())
            .andReturn(featuresReply.getNBuffers()).anyTimes();
    expect(sw.getTables())
            .andReturn(featuresReply.getNTables()).anyTimes();
    expect(sw.getCapabilities())
            .andReturn(featuresReply.getCapabilities()).anyTimes();
    expect(sw.getActions())
            .andReturn(featuresReply.getActions()).anyTimes();
    expect(sw.getPorts())
            .andReturn(ports).anyTimes();
    expect(sw.attributeEquals(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE, true))
            .andReturn(false).anyTimes();
    expect(sw.getInetAddress()).andReturn(null).anyTimes();
}
项目:iTAP-controller    文件:OFSwitchManagerTest.java   
/**
 * Create and activate a new switch with the given dpid, features reply
 * and description. If description and/or features reply are null we'll
 * allocate the default one
 * The mocked switch instance will be returned. It wil be reset.
 */
private IOFSwitchBackend doActivateNewSwitch(DatapathId dpid,
                                      SwitchDescription description,
                                      OFFeaturesReply featuresReply)
                                      throws Exception {
    return doActivateSwitchInt(dpid, description, featuresReply, true);
}
项目:iTAP-controller    文件:OFSwitchHandshakeHandlerVer13Test.java   
public void handleDescStatsAndCreateSwitch(boolean subHandShakeComplete) throws Exception {
    // build the stats reply
    OFDescStatsReply sr = createDescriptionStatsReply();

    reset(sw);
    SwitchDescription switchDescription = new SwitchDescription(sr);
    setupSwitchForInstantiationWithReset();
    sw.setPortDescStats(anyObject(OFPortDescStatsReply.class));
    expectLastCall().once();
    sw.startDriverHandshake();
    expectLastCall().once();
    expect(sw.isDriverHandshakeComplete()).andReturn(subHandShakeComplete).once();
    replay(sw);

    reset(switchManager);
    expect(switchManager.getHandshakePlugins()).andReturn(plugins).anyTimes();
    expect(
           switchManager.getOFSwitchInstance(anyObject(OFConnection.class),
                                          eq(switchDescription),
                                          anyObject(OFFactory.class),
                                          anyObject(DatapathId.class))).andReturn(sw).once();
    expect(switchManager.getNumRequiredConnections()).andReturn(1).anyTimes(); 
    switchManager.switchAdded(sw);
    expectLastCall().once();
    replay(switchManager);

    // send the description stats reply
    switchHandler.processOFMessage(sr);

    verify(sw, switchManager);
}
项目:iTAP-controller    文件:ControllerTest.java   
/** Set the mock expectations for sw when sw is passed to addSwitch
 * The same expectations can be used when a new SwitchSyncRepresentation
 * is created from the given mocked switch */
protected void setupSwitchForAddSwitch(IOFSwitch sw, DatapathId datapathId,
                                       SwitchDescription description,
                                       OFFeaturesReply featuresReply) {
    String dpidString = datapathId.toString();
    if (description == null) {
        description = createSwitchDescription();
    }
    if (featuresReply == null) {
        featuresReply = createOFFeaturesReply(datapathId);
    }
    List<OFPortDesc> ports = featuresReply.getPorts();

    expect(sw.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_10)).anyTimes();
    expect(sw.getId()).andReturn(datapathId).anyTimes();
    expect(sw.getId().toString()).andReturn(dpidString).anyTimes();
    expect(sw.getSwitchDescription()).andReturn(description).atLeastOnce();
    expect(sw.getBuffers())
            .andReturn(featuresReply.getNBuffers()).atLeastOnce();
    expect(sw.getTables())
            .andReturn(featuresReply.getNTables()).atLeastOnce();
    expect(sw.getCapabilities())
            .andReturn(featuresReply.getCapabilities()).atLeastOnce();
    expect(sw.getActions())
            .andReturn(featuresReply.getActions()).atLeastOnce();
    expect(sw.getPorts())
            .andReturn(ports).atLeastOnce();
    expect(sw.attributeEquals(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE, true))
            .andReturn(false).anyTimes();
    expect(sw.getInetAddress()).andReturn(null).anyTimes();
}
项目:iTAP-controller    文件:OFSwitchHandshakeHandlerVer10Test.java   
public void handleDescStatsAndCreateSwitch(boolean switchDriverComplete) throws Exception {
    // build the stats reply
    OFDescStatsReply sr = createDescriptionStatsReply();

    reset(sw);
    SwitchDescription switchDescription = new SwitchDescription(sr);
    setupSwitchForInstantiationWithReset();
    sw.startDriverHandshake();
    expectLastCall().once();
    sw.isDriverHandshakeComplete();
    expectLastCall().andReturn(switchDriverComplete).once();

    if(factory.getVersion().compareTo(OFVersion.OF_13) >= 0) {
        sw.setPortDescStats(anyObject(OFPortDescStatsReply.class));
        expectLastCall().once();
    }

    replay(sw);

    reset(switchManager);
    expect(switchManager.getHandshakePlugins()).andReturn(plugins).anyTimes();
    expect(
           switchManager.getOFSwitchInstance(anyObject(OFConnection.class),
                                          eq(switchDescription),
                                          anyObject(OFFactory.class),
                                          anyObject(DatapathId.class))).andReturn(sw).once();
    switchManager.switchAdded(sw);
    expectLastCall().once();
    replay(switchManager);

    // send the description stats reply
    switchHandler.processOFMessage(sr);
}
项目:iTAP-controller    文件:MockSwitchManager.java   
@Override
public IOFSwitchBackend
        getOFSwitchInstance(IOFConnectionBackend connection,
                            SwitchDescription description,
                            OFFactory factory, DatapathId datapathId) {
    return null;
}
项目:SDN-Multicast    文件:IOFSwitchSerializer.java   
public void serializeDescription(SwitchDescription swDescription, JsonGenerator jGen)
        throws IOException, JsonProcessingException {
    if( null == swDescription)
        jGen.writeStringField("description","null");
    else{
        jGen.writeFieldName("description");
        jGen.writeStartObject();
        jGen.writeStringField("datapath",swDescription.getDatapathDescription());
        jGen.writeStringField("hardware",swDescription.getHardwareDescription());
        jGen.writeStringField("manufacturer",swDescription.getManufacturerDescription());
        jGen.writeStringField("serialNum",swDescription.getSerialNumber());
        jGen.writeStringField("software",swDescription.getSoftwareDescription());
        jGen.writeEndObject();
    }
}
项目:SDN-Multicast    文件:SwitchSyncRepresentation.java   
public SwitchSyncRepresentation(OFFeaturesReply fr,
                                SwitchDescription d) {
    this.dpid = fr.getDatapathId();
    this.buffers = fr.getNBuffers();
    this.tables = fr.getNTables();
    this.capabilities = fr.getCapabilities();
    this.actions = fr.getActions();
    this.ports = toSyncedPortList(fr.getPorts());

    this.manufacturerDescription = d.getManufacturerDescription();
    this.hardwareDescription = d.getHardwareDescription();
    this.softwareDescription = d.getSoftwareDescription();
    this.serialNumber = d.getSerialNumber();
    this.datapathDescription = d.getDatapathDescription();
}
项目:SDN-Multicast    文件:OFSwitch.java   
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>();
}
项目:SDN-Multicast    文件:OFSwitchHandshakeHandler.java   
void handlePendingPortStatusMessages(SwitchDescription description){
    for (OFPortStatus ps: pendingPortStatusMsg) {
        handlePortStatusMessage(ps, false);
    }
    pendingPortStatusMsg.clear();
    log.info("Switch {} bound to class {}, description {}", new Object[] { sw, sw.getClass(), description });
}
项目:floodlight-hardware    文件:MockSwitchManager.java   
@Override
public IOFSwitchBackend
        getOFSwitchInstance(IOFConnectionBackend connection,
                            SwitchDescription description,
                            OFFactory factory, DatapathId datapathId) {
    return null;
}
项目:SDN-Multicast    文件:OFSwitchManagerTest.java   
/** Set the mock expectations for sw when sw is passed to addSwitch
 * The same expectations can be used when a new SwitchSyncRepresentation
 * is created from the given mocked switch */
protected void setupSwitchForAddSwitch(IOFSwitch sw, DatapathId datapathId,
        SwitchDescription description, OFFeaturesReply featuresReply) {
    if (description == null) {
        description = createSwitchDescription();
    }
    if (featuresReply == null) {
        featuresReply = createOFFeaturesReply(datapathId);
    }
    List<OFPortDesc> ports = featuresReply.getPorts();

    expect(sw.getOFFactory()).andReturn(OFFactories.getFactory(OFVersion.OF_10)).anyTimes();
    expect(sw.getStatus()).andReturn(SwitchStatus.MASTER).anyTimes();
    expect(sw.getId()).andReturn(datapathId).anyTimes();
    expect(sw.getSwitchDescription()).andReturn(description).anyTimes();
    expect(sw.getBuffers())
            .andReturn(featuresReply.getNBuffers()).anyTimes();
    expect(sw.getNumTables())
            .andReturn(featuresReply.getNTables()).anyTimes();
    expect(sw.getCapabilities())
            .andReturn(featuresReply.getCapabilities()).anyTimes();
    expect(sw.getActions())
            .andReturn(featuresReply.getActions()).anyTimes();
    expect(sw.getPorts())
            .andReturn(ports).anyTimes();
    expect(sw.attributeEquals(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE, true))
            .andReturn(false).anyTimes();
    expect(sw.getInetAddress()).andReturn(null).anyTimes();
}