Search in sources :

Example 1 with OpenFlowSwitchDriver

use of org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver in project onos by opennetworkinglab.

the class Controller method getOFSwitchInstance.

/**
 * Forward to the driver-manager to get an IOFSwitch instance.
 *
 * @param dpid data path id
 * @param desc switch description
 * @param ofv  OpenFlow version
 * @return switch instance
 */
protected OpenFlowSwitchDriver getOFSwitchInstance(long dpid, OFDescStatsReply desc, OFVersion ofv) {
    Dpid dpidObj = new Dpid(dpid);
    Driver driver;
    try {
        driver = driverService.getDriver(DeviceId.deviceId(Dpid.uri(dpidObj)));
    } catch (ItemNotFoundException e) {
        driver = driverService.getDriver(desc.getMfrDesc(), desc.getHwDesc(), desc.getSwDesc());
    }
    if (driver == null) {
        log.error("No OpenFlow driver for {} : {}", dpidObj, desc);
        return null;
    }
    log.info("Driver '{}' assigned to device {}", driver.name(), dpidObj);
    if (!driver.hasBehaviour(OpenFlowSwitchDriver.class)) {
        log.error("Driver {} does not support OpenFlowSwitchDriver behaviour", driver.name());
        return null;
    }
    DefaultDriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId(uri(dpidObj))));
    OpenFlowSwitchDriver ofSwitchDriver = driver.createBehaviour(handler, OpenFlowSwitchDriver.class);
    ofSwitchDriver.init(dpidObj, desc, ofv);
    ofSwitchDriver.setAgent(agent);
    ofSwitchDriver.setRoleHandler(new RoleManager(ofSwitchDriver));
    return ofSwitchDriver;
}
Also used : OpenFlowSwitchDriver(org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) Dpid(org.onosproject.openflow.controller.Dpid) Driver(org.onosproject.net.driver.Driver) OpenFlowSwitchDriver(org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver) ItemNotFoundException(org.onlab.util.ItemNotFoundException) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData)

Example 2 with OpenFlowSwitchDriver

use of org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver in project onos by opennetworkinglab.

the class ControllerTest method switchItemNotFoundTest.

/**
 * Tests fetching a driver that throws an ItemNotFoundException.
 */
@Test
public void switchItemNotFoundTest() {
    controller.start(null, new MockDriverService(), null);
    OFDescStatsReply stats = new OFDescStatsReplyAdapter();
    OpenFlowSwitchDriver driver = controller.getOFSwitchInstance(MockDriverService.ITEM_NOT_FOUND_DRIVER_ID, stats, null);
    assertThat(driver, nullValue());
    controller.stop();
}
Also used : OFDescStatsReply(org.projectfloodlight.openflow.protocol.OFDescStatsReply) OpenFlowSwitchDriver(org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver) OFDescStatsReplyAdapter(org.onosproject.openflow.OFDescStatsReplyAdapter) Test(org.junit.Test)

Example 3 with OpenFlowSwitchDriver

use of org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver in project onos by opennetworkinglab.

the class ControllerTest method driverExistsTest.

/**
 * Tests fetching a driver that throws an ItemNotFoundException.
 */
@Test
public void driverExistsTest() {
    controller.start(null, new MockDriverService(), null);
    OFDescStatsReply stats = new OFDescStatsReplyAdapter();
    OpenFlowSwitchDriver driver = controller.getOFSwitchInstance(MockDriverService.DRIVER_EXISTS_ID, stats, null);
    assertThat(driver, notNullValue());
    controller.stop();
}
Also used : OFDescStatsReply(org.projectfloodlight.openflow.protocol.OFDescStatsReply) OpenFlowSwitchDriver(org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver) OFDescStatsReplyAdapter(org.onosproject.openflow.OFDescStatsReplyAdapter) Test(org.junit.Test)

Example 4 with OpenFlowSwitchDriver

use of org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver in project onos by opennetworkinglab.

the class ControllerTest method switchInstanceNotFoundTest.

/**
 * Tests fetching a driver that does not exist.
 */
@Test
public void switchInstanceNotFoundTest() {
    controller.start(null, new MockDriverService(), null);
    OpenFlowSwitchDriver driver = controller.getOFSwitchInstance(MockDriverService.NO_SUCH_DRIVER_ID, null, null);
    assertThat(driver, nullValue());
    controller.stop();
}
Also used : OpenFlowSwitchDriver(org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver) Test(org.junit.Test)

Aggregations

OpenFlowSwitchDriver (org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver)4 Test (org.junit.Test)3 OFDescStatsReplyAdapter (org.onosproject.openflow.OFDescStatsReplyAdapter)2 OFDescStatsReply (org.projectfloodlight.openflow.protocol.OFDescStatsReply)2 ItemNotFoundException (org.onlab.util.ItemNotFoundException)1 DefaultDriverData (org.onosproject.net.driver.DefaultDriverData)1 DefaultDriverHandler (org.onosproject.net.driver.DefaultDriverHandler)1 Driver (org.onosproject.net.driver.Driver)1 Dpid (org.onosproject.openflow.controller.Dpid)1