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);
}
}
}
}
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());
}
}
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());
}
}
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;
}
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));
}
Aggregations