Search in sources :

Example 61 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class FujitsuVoltNeConfig method getAll.

@Override
public String getAll() {
    DriverHandler handler = handler();
    NetconfController controller = handler.get(NetconfController.class);
    MastershipService mastershipService = handler.get(MastershipService.class);
    DeviceId ncDeviceId = handler.data().deviceId();
    checkNotNull(controller, "Netconf controller is null");
    String reply = null;
    if (!mastershipService.isLocalMaster(ncDeviceId)) {
        log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
        return null;
    }
    try {
        StringBuilder request = new StringBuilder();
        request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE);
        request.append(ANGLE_RIGHT + NEW_LINE);
        request.append(VOLT_NE_CLOSE);
        reply = controller.getDevicesMap().get(ncDeviceId).getSession().get(request.toString(), REPORT_ALL);
    } catch (NetconfException e) {
        log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
    }
    return reply;
}
Also used : NetconfException(org.onosproject.netconf.NetconfException) DeviceId(org.onosproject.net.DeviceId) DriverHandler(org.onosproject.net.driver.DriverHandler) MastershipService(org.onosproject.mastership.MastershipService) NetconfController(org.onosproject.netconf.NetconfController)

Example 62 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class OpenFlowPolicerConfigurableTest method testMeterNull.

/**
 * Test meter problems.
 */
@Test
public void testMeterNull() {
    // Get device handler
    DriverHandler driverHandler = driverService.createHandler(ofDid);
    // Get policer config behavior
    PolicerConfigurable policerConfigurable = driverHandler.behaviour(PolicerConfigurable.class);
    // Get policer id
    PolicerId policerId = policerConfigurable.allocatePolicerId();
    // this works
    assertThat(policerId.uri().getScheme(), is(OF_SCHEME));
    String hexId = Long.toHexString((mid1.id()));
    assertThat(policerId.uri().getSchemeSpecificPart(), is(hexId));
    // Get another policer id
    policerId = policerConfigurable.allocatePolicerId();
    assertThat(policerId.uri().getScheme(), is(OF_SCHEME));
    hexId = Long.toHexString((mid10.id()));
    assertThat(policerId.uri().getSchemeSpecificPart(), is(hexId));
    // Get the last policer id
    policerId = policerConfigurable.allocatePolicerId();
    assertThat(policerId.uri().getScheme(), is(OF_SCHEME));
    hexId = Long.toHexString((mid100.id()));
    assertThat(policerId.uri().getSchemeSpecificPart(), is(hexId));
    // this does not work
    policerId = policerConfigurable.allocatePolicerId();
    // Assert that is none
    assertThat(policerId, is(PolicerId.NONE));
}
Also used : DriverHandler(org.onosproject.net.driver.DriverHandler) PolicerId(org.onosproject.net.behaviour.trafficcontrol.PolicerId) PolicerConfigurable(org.onosproject.net.behaviour.trafficcontrol.PolicerConfigurable) Test(org.junit.Test)

Example 63 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class OpenFlowPolicerConfigurableTest method testFreeId.

/**
 * Test free policer id.
 */
@Test
public void testFreeId() {
    // Get device handler
    DriverHandler driverHandler = driverService.createHandler(ofDid);
    // Get policer config behavior
    PolicerConfigurable policerConfigurable = driverHandler.behaviour(PolicerConfigurable.class);
    // Get policer id
    PolicerId policerId = policerConfigurable.allocatePolicerId();
    // this works
    assertThat(policerId.uri().getScheme(), is(OF_SCHEME));
    String hexId = Long.toHexString((mid1.id()));
    assertThat(policerId.uri().getSchemeSpecificPart(), is(hexId));
    // Verify the allocation before free
    assertThat(meterService.availableIds.size(), is(2));
    // Let's free the policer id
    policerConfigurable.freePolicerId(policerId);
    // Verify the availability after free
    assertThat(meterService.availableIds.size(), is(3));
}
Also used : DriverHandler(org.onosproject.net.driver.DriverHandler) PolicerId(org.onosproject.net.behaviour.trafficcontrol.PolicerId) PolicerConfigurable(org.onosproject.net.behaviour.trafficcontrol.PolicerConfigurable) Test(org.junit.Test)

Example 64 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class DellRestBridgeConfig method addPort.

@Override
public void addPort(BridgeName bridgeName, String portName) {
    // bridgeName is not used
    checkNotNull(portName);
    portName = portNameForCli(portName);
    String portAddCommands = String.format(PORT_ADD_COMMANDS, portName);
    DriverHandler handler = handler();
    RestSBController controller = checkNotNull(handler.get(RestSBController.class));
    DeviceId deviceId = handler.data().deviceId();
    InputStream payload = new StringBufferInputStream(String.format(CONFIG_COMMANDS, portAddCommands));
    String resp = controller.post(deviceId, CLI_REQUEST, payload, MediaType.valueOf("*/*"), String.class);
    // TODO Parse resp and if error, return false
    log.info("{}", resp);
    return;
}
Also used : StringBufferInputStream(java.io.StringBufferInputStream) RestSBController(org.onosproject.protocol.rest.RestSBController) DeviceId(org.onosproject.net.DeviceId) StringBufferInputStream(java.io.StringBufferInputStream) InputStream(java.io.InputStream) DriverHandler(org.onosproject.net.driver.DriverHandler)

Example 65 with DriverHandler

use of org.onosproject.net.driver.DriverHandler in project onos by opennetworkinglab.

the class DellRestBridgeConfig method deletePort.

@Override
public void deletePort(BridgeName bridgeName, String portName) {
    // bridgeName is not used
    checkNotNull(portName);
    portName = portNameForCli(portName);
    String portRemoveCommands = String.format(PORT_REMOVE_COMMANDS, portName);
    DriverHandler handler = handler();
    RestSBController controller = checkNotNull(handler.get(RestSBController.class));
    DeviceId deviceId = handler.data().deviceId();
    InputStream payload = new StringBufferInputStream(String.format(CONFIG_COMMANDS, portRemoveCommands));
    String resp = controller.post(deviceId, CLI_REQUEST, payload, MediaType.valueOf("*/*"), String.class);
    log.info("{}", resp);
}
Also used : StringBufferInputStream(java.io.StringBufferInputStream) RestSBController(org.onosproject.protocol.rest.RestSBController) DeviceId(org.onosproject.net.DeviceId) StringBufferInputStream(java.io.StringBufferInputStream) InputStream(java.io.InputStream) DriverHandler(org.onosproject.net.driver.DriverHandler)

Aggregations

DriverHandler (org.onosproject.net.driver.DriverHandler)104 DeviceId (org.onosproject.net.DeviceId)46 DriverService (org.onosproject.net.driver.DriverService)22 NetconfController (org.onosproject.netconf.NetconfController)22 NetconfException (org.onosproject.netconf.NetconfException)22 MastershipService (org.onosproject.mastership.MastershipService)20 ArrayList (java.util.ArrayList)12 DefaultDriverHandler (org.onosproject.net.driver.DefaultDriverHandler)12 ItemNotFoundException (org.onlab.util.ItemNotFoundException)9 DeviceService (org.onosproject.net.device.DeviceService)9 OvsdbClientService (org.onosproject.ovsdb.controller.OvsdbClientService)9 DefaultDriverData (org.onosproject.net.driver.DefaultDriverData)8 Driver (org.onosproject.net.driver.Driver)8 Test (org.junit.Test)7 ControllerInfo (org.onosproject.net.behaviour.ControllerInfo)6 RestSBController (org.onosproject.protocol.rest.RestSBController)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 PolicerConfigurable (org.onosproject.net.behaviour.trafficcontrol.PolicerConfigurable)5 PolicerId (org.onosproject.net.behaviour.trafficcontrol.PolicerId)5