use of org.onosproject.incubator.net.virtual.VirtualDevice in project onos by opennetworkinglab.
the class VirtualPortCreateCommand method doExecute.
@Override
protected void doExecute() {
VirtualNetworkAdminService service = get(VirtualNetworkAdminService.class);
DeviceService deviceService = get(DeviceService.class);
VirtualDevice virtualDevice = getVirtualDevice(DeviceId.deviceId(deviceId));
checkNotNull(virtualDevice, "The virtual device does not exist.");
ConnectPoint realizedBy = null;
if (physDeviceId != null && physPortNum != null) {
checkNotNull(physPortNum, "The physical port does not specified.");
realizedBy = new ConnectPoint(DeviceId.deviceId(physDeviceId), PortNumber.portNumber(physPortNum));
checkNotNull(realizedBy, "The physical port does not exist.");
}
service.createVirtualPort(NetworkId.networkId(networkId), DeviceId.deviceId(deviceId), PortNumber.portNumber(portNum), realizedBy);
print("Virtual port successfully created.");
}
use of org.onosproject.incubator.net.virtual.VirtualDevice in project onos by opennetworkinglab.
the class VirtualDeviceListCommand method getSortedVirtualDevices.
/**
* Returns the list of virtual devices sorted using the device identifier.
*
* @return sorted virtual device list
*/
private List<VirtualDevice> getSortedVirtualDevices() {
VirtualNetworkService service = get(VirtualNetworkService.class);
List<VirtualDevice> virtualDevices = new ArrayList<>();
virtualDevices.addAll(service.getVirtualDevices(NetworkId.networkId(networkId)));
Collections.sort(virtualDevices, Comparators.VIRTUAL_DEVICE_COMPARATOR);
return virtualDevices;
}
use of org.onosproject.incubator.net.virtual.VirtualDevice in project onos by opennetworkinglab.
the class VirtualNetworkDeviceManagerTest method testGetPorts.
/**
* Tests querying the ports of a device by device identifier.
*/
@Test
public void testGetPorts() {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
VirtualDevice virtualDevice = manager.createVirtualDevice(virtualNetwork.id(), DID1);
manager.createVirtualDevice(virtualNetwork.id(), DID2);
DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
ConnectPoint cp = new ConnectPoint(virtualDevice.id(), PortNumber.portNumber(1));
manager.createVirtualPort(virtualNetwork.id(), virtualDevice.id(), PortNumber.portNumber(1), cp);
manager.createVirtualPort(virtualNetwork.id(), virtualDevice.id(), PortNumber.portNumber(2), cp);
// test the getPorts() method
assertEquals("The port set size did not match.", 2, deviceService.getPorts(DID1).size());
assertEquals("The port set size did not match.", 0, deviceService.getPorts(DID2).size());
}
use of org.onosproject.incubator.net.virtual.VirtualDevice in project onos by opennetworkinglab.
the class VirtualNetworkDeviceManagerTest method testGetDevices.
/**
* Tests the getDevices(), getAvailableDevices(), getDeviceCount(), getDevice(), and isAvailable() methods.
*/
@Test
public void testGetDevices() {
manager.registerTenantId(TenantId.tenantId(tenantIdValue1));
VirtualNetwork virtualNetwork = manager.createVirtualNetwork(TenantId.tenantId(tenantIdValue1));
VirtualDevice device1 = manager.createVirtualDevice(virtualNetwork.id(), DID1);
VirtualDevice device2 = manager.createVirtualDevice(virtualNetwork.id(), DID2);
DeviceService deviceService = manager.get(virtualNetwork.id(), DeviceService.class);
// test the getDevices() method
Iterator<Device> it = deviceService.getDevices().iterator();
assertEquals("The device set size did not match.", 2, Iterators.size(it));
// test the getAvailableDevices() method
Iterator<Device> it2 = deviceService.getAvailableDevices().iterator();
assertEquals("The device set size did not match.", 2, Iterators.size(it2));
// test the getDeviceCount() method
assertEquals("The device set size did not match.", 2, deviceService.getDeviceCount());
// test the getDevice() method
assertEquals("The expect device did not match.", device1, deviceService.getDevice(DID1));
assertNotEquals("The expect device should not have matched.", device1, deviceService.getDevice(DID2));
// test the isAvailable() method
assertTrue("The expect device availability did not match.", deviceService.isAvailable(DID1));
assertFalse("The expect device availability did not match.", deviceService.isAvailable(DID3));
}
use of org.onosproject.incubator.net.virtual.VirtualDevice in project onos by opennetworkinglab.
the class VirtualNetworkWebResource method getVirtualDevices.
// VirtualDevice
/**
* Returns all virtual network devices in a virtual network.
*
* @param networkId network identifier
* @return 200 OK with set of virtual devices, 404 not found
* @onos.rsModel VirtualDevices
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{networkId}/devices")
public Response getVirtualDevices(@PathParam("networkId") long networkId) {
NetworkId nid = NetworkId.networkId(networkId);
Set<VirtualDevice> vdevs = vnetService.getVirtualDevices(nid);
return ok(encodeArray(VirtualDevice.class, "devices", vdevs)).build();
}
Aggregations