Search in sources :

Example 76 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class MappingsListCommand method doExecute.

@Override
protected void doExecute() {
    MappingStore.Type typeEnum = getTypeEnum(type);
    DeviceService deviceService = get(DeviceService.class);
    Iterable<Device> devices = deviceService.getDevices();
    if (outputJson()) {
        print(JSON_FORMAT, json(typeEnum, devices));
    } else {
        if (deviceId != null) {
            mappings = newArrayList(mappingService.getMappingEntries(typeEnum, DeviceId.deviceId(deviceId)));
            printMappings(DeviceId.deviceId(deviceId), mappings);
        } else {
            for (Device d : devices) {
                mappings = newArrayList(mappingService.getMappingEntries(typeEnum, d.id()));
                printMappings(d.id(), mappings);
            }
        }
    }
}
Also used : Device(org.onosproject.net.Device) DeviceService(org.onosproject.net.device.DeviceService) MappingStore(org.onosproject.mapping.MappingStore)

Example 77 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class VplsWebResource method addInterfaces.

/**
 * Add new interfaces. Add new interfaces to a Vpls.<br>
 *
 * @param stream interfaces JSON
 * @param vplsName Vpls name
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel InterfacesPost
 */
@POST
@Path("interfaces/{vplsName}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response addInterfaces(@PathParam("vplsName") String vplsName, InputStream stream) {
    Vpls service = get(Vpls.class);
    DeviceService deviceService = get(DeviceService.class);
    InterfaceAdminService interfaceService = get(InterfaceAdminService.class);
    final VplsData vplsData = nullIsNotFound(service.getVpls(vplsName), VPLS_NOT_FOUND + vplsName);
    try {
        ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
        ArrayNode routesArray = nullIsIllegal((ArrayNode) jsonTree.get(INTERFACES), INTERFACES_KEY_ERROR);
        Collection<Interface> interfaceList = new ArrayList<>();
        routesArray.forEach(interfJson -> {
            Interface inter = codec(Interface.class).decode((ObjectNode) interfJson, this);
            nullIsNotFound(deviceService.getDevice(inter.connectPoint().deviceId()), DEVICE_NOT_FOUND + inter.connectPoint().deviceId());
            nullIsNotFound(deviceService.getPort(inter.connectPoint()), PORT_NOT_FOUND + inter.connectPoint().port());
            interfaceList.add(inter);
            interfaceService.add(inter);
        });
        service.addInterfaces(vplsData, interfaceList);
        UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path(INTERFACES).path(vplsName);
        return Response.created(locationBuilder.build()).build();
    } catch (IOException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
}
Also used : InterfaceAdminService(org.onosproject.net.intf.InterfaceAdminService) VplsData(org.onosproject.vpls.api.VplsData) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceService(org.onosproject.net.device.DeviceService) ArrayList(java.util.ArrayList) Vpls(org.onosproject.vpls.api.Vpls) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) Interface(org.onosproject.net.intf.Interface) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 78 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class VplsWebResource method createVpls.

/**
 * Creates new vpls. Creates and installs a new Vplps.<br>
 *
 * @param stream Vpls JSON
 * @return status of the request - CREATED if the JSON is correct,
 * BAD_REQUEST if the JSON is invalid
 * @onos.rsModel VplsPost
 */
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createVpls(InputStream stream) {
    Vpls service = get(Vpls.class);
    DeviceService deviceService = get(DeviceService.class);
    InterfaceAdminService interfaceService = get(InterfaceAdminService.class);
    try {
        ObjectNode jsonTree = readTreeFromStream(mapper(), stream);
        VplsData vplsData = codec(VplsData.class).decode(jsonTree, this);
        vplsData.interfaces().forEach(interf -> {
            nullIsNotFound(deviceService.getDevice(interf.connectPoint().deviceId()), DEVICE_NOT_FOUND + interf.connectPoint().deviceId());
            nullIsNotFound(deviceService.getPort(interf.connectPoint()), PORT_NOT_FOUND + interf.connectPoint().port());
            interfaceService.add(interf);
        });
        service.addInterfaces(vplsData, vplsData.interfaces());
        UriBuilder locationBuilder = uriInfo.getBaseUriBuilder().path(VPLS);
        return Response.created(locationBuilder.build()).build();
    } catch (IOException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
}
Also used : InterfaceAdminService(org.onosproject.net.intf.InterfaceAdminService) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) VplsData(org.onosproject.vpls.api.VplsData) DeviceService(org.onosproject.net.device.DeviceService) Vpls(org.onosproject.vpls.api.Vpls) IOException(java.io.IOException) UriBuilder(javax.ws.rs.core.UriBuilder) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 79 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class DefaultKubevirtNode method tunnelPort.

private PortNumber tunnelPort(String tunnelType) {
    if (dataIp == null) {
        return null;
    }
    DeviceService deviceService = DefaultServiceDirectory.getService(DeviceService.class);
    Port port = deviceService.getPorts(tunBridge).stream().filter(p -> p.isEnabled() && Objects.equals(p.annotations().value(PORT_NAME), tunnelType)).findAny().orElse(null);
    return port != null ? port.number() : null;
}
Also used : Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService)

Example 80 with DeviceService

use of org.onosproject.net.device.DeviceService in project onos by opennetworkinglab.

the class OpenstackNetworkingUtilTest method testHasIntfAleadyInDevice.

/**
 * Tests hasIntfAleadyInDevice method.
 */
@Test
public void testHasIntfAleadyInDevice() {
    DeviceService deviceService = new TestDeviceService();
    assertTrue(OpenstackNetworkingUtil.hasIntfAleadyInDevice(DeviceId.deviceId("deviceId"), "port1", deviceService));
    assertTrue(OpenstackNetworkingUtil.hasIntfAleadyInDevice(DeviceId.deviceId("deviceId"), "port2", deviceService));
    assertTrue(OpenstackNetworkingUtil.hasIntfAleadyInDevice(DeviceId.deviceId("deviceId"), "port3", deviceService));
    assertFalse(OpenstackNetworkingUtil.hasIntfAleadyInDevice(DeviceId.deviceId("deviceId"), "port4", deviceService));
}
Also used : DeviceService(org.onosproject.net.device.DeviceService) OpenstackNodeTest(org.onosproject.openstacknode.api.OpenstackNodeTest) Test(org.junit.Test) OpenstackFloatingIpWebResourceTest(org.onosproject.openstacknetworking.web.OpenstackFloatingIpWebResourceTest) OpenstackNetworkWebResourceTest(org.onosproject.openstacknetworking.web.OpenstackNetworkWebResourceTest)

Aggregations

DeviceService (org.onosproject.net.device.DeviceService)187 Device (org.onosproject.net.Device)75 DeviceId (org.onosproject.net.DeviceId)73 Port (org.onosproject.net.Port)59 ConnectPoint (org.onosproject.net.ConnectPoint)42 PortNumber (org.onosproject.net.PortNumber)40 List (java.util.List)30 Collectors (java.util.stream.Collectors)24 Set (java.util.Set)23 AbstractHandlerBehaviour (org.onosproject.net.driver.AbstractHandlerBehaviour)19 Logger (org.slf4j.Logger)19 ArrayList (java.util.ArrayList)18 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)17 Optional (java.util.Optional)17 Test (org.junit.Test)16 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Collections (java.util.Collections)15 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)15 DriverHandler (org.onosproject.net.driver.DriverHandler)15 Collection (java.util.Collection)14