use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.
the class VirtualNetworkCompleter method complete.
@Override
public int complete(Session session, CommandLine commandLine, List<String> candidates) {
// Delegate string completer
StringsCompleter delegate = new StringsCompleter();
// Fetch our service and feed it's offerings to the string completer
VirtualNetworkAdminService service = AbstractShellCommand.get(VirtualNetworkAdminService.class);
List<VirtualNetwork> virtualNetworks = new ArrayList<>();
Set<TenantId> tenantSet = service.getTenantIds();
tenantSet.forEach(tenantId -> virtualNetworks.addAll(service.getVirtualNetworks(tenantId)));
Collections.sort(virtualNetworks, Comparators.VIRTUAL_NETWORK_COMPARATOR);
SortedSet<String> strings = delegate.getStrings();
virtualNetworks.forEach(virtualNetwork -> strings.add(virtualNetwork.id().toString()));
// Now let the completer do the work for figuring out what to offer.
return delegate.complete(session, commandLine, candidates);
}
use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.
the class VirtualNetworkListCommand method getSortedVirtualNetworks.
/**
* Returns the list of virtual networks sorted using the tenant identifier.
*
* @return sorted virtual network list
*/
private List<VirtualNetwork> getSortedVirtualNetworks() {
VirtualNetworkService service = get(VirtualNetworkService.class);
VirtualNetworkAdminService adminService = get(VirtualNetworkAdminService.class);
List<VirtualNetwork> virtualNetworks = new ArrayList<>();
Set<TenantId> tenantSet = adminService.getTenantIds();
tenantSet.forEach(tenantId -> virtualNetworks.addAll(service.getVirtualNetworks(tenantId)));
Collections.sort(virtualNetworks, Comparators.VIRTUAL_NETWORK_COMPARATOR);
return virtualNetworks;
}
use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.
the class VirtualNetworkManager method create.
/**
* Create a new vnet service instance.
*
* @param serviceKey service key
* @return vnet service
*/
private VnetService create(ServiceKey serviceKey) {
VirtualNetwork network = getVirtualNetwork(serviceKey.networkId());
checkNotNull(network, NETWORK_NULL);
VnetService service;
if (serviceKey.serviceClass.equals(DeviceService.class)) {
service = new VirtualNetworkDeviceManager(this, network.id());
} else if (serviceKey.serviceClass.equals(LinkService.class)) {
service = new VirtualNetworkLinkManager(this, network.id());
} else if (serviceKey.serviceClass.equals(TopologyService.class)) {
service = new VirtualNetworkTopologyManager(this, network.id());
} else if (serviceKey.serviceClass.equals(IntentService.class)) {
service = new VirtualNetworkIntentManager(this, network.id());
} else if (serviceKey.serviceClass.equals(HostService.class)) {
service = new VirtualNetworkHostManager(this, network.id());
} else if (serviceKey.serviceClass.equals(PathService.class)) {
service = new VirtualNetworkPathManager(this, network.id());
} else if (serviceKey.serviceClass.equals(FlowRuleService.class)) {
service = new VirtualNetworkFlowRuleManager(this, network.id());
} else if (serviceKey.serviceClass.equals(PacketService.class)) {
service = new VirtualNetworkPacketManager(this, network.id());
} else if (serviceKey.serviceClass.equals(GroupService.class)) {
service = new VirtualNetworkGroupManager(this, network.id());
} else if (serviceKey.serviceClass.equals(MeterService.class)) {
service = new VirtualNetworkMeterManager(this, network.id());
} else if (serviceKey.serviceClass.equals(FlowObjectiveService.class)) {
service = new VirtualNetworkFlowObjectiveManager(this, network.id());
} else if (serviceKey.serviceClass.equals(MastershipService.class) || serviceKey.serviceClass.equals(MastershipAdminService.class) || serviceKey.serviceClass.equals(MastershipTermService.class)) {
service = new VirtualNetworkMastershipManager(this, network.id());
} else {
return null;
}
networkServices.put(serviceKey, service);
return service;
}
use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.
the class DistributedVirtualNetworkStore method removeNetwork.
@Override
public void removeNetwork(NetworkId networkId) {
// Make sure that the virtual network exists before attempting to remove it.
checkState(networkExists(networkId), "The network does not exist.");
// Remove all the devices of this network
Set<VirtualDevice> deviceSet = getDevices(networkId);
if (deviceSet != null) {
deviceSet.forEach(virtualDevice -> removeDevice(networkId, virtualDevice.id()));
}
// TODO update both maps in one transaction.
VirtualNetwork virtualNetwork = networkIdVirtualNetworkMap.remove(networkId);
if (virtualNetwork == null) {
return;
}
TenantId tenantId = virtualNetwork.tenantId();
Set<NetworkId> networkIdSet = new HashSet<>();
tenantIdNetworkIdSetMap.get(tenantId).forEach(networkId1 -> {
if (networkId1.id().equals(networkId.id())) {
networkIdSet.add(networkId1);
}
});
tenantIdNetworkIdSetMap.compute(virtualNetwork.tenantId(), (id, existingNetworkIds) -> {
if (existingNetworkIds == null || existingNetworkIds.isEmpty()) {
return new HashSet<>();
} else {
return new HashSet<>(Sets.difference(existingNetworkIds, networkIdSet));
}
});
}
use of org.onosproject.incubator.net.virtual.VirtualNetwork in project onos by opennetworkinglab.
the class DistributedVirtualNetworkStore method addNetwork.
@Override
public VirtualNetwork addNetwork(TenantId tenantId) {
checkState(tenantIdSet.contains(tenantId), "The tenant has not been registered. " + tenantId.id());
VirtualNetwork virtualNetwork = new DefaultVirtualNetwork(genNetworkId(), tenantId);
// TODO update both maps in one transaction.
networkIdVirtualNetworkMap.put(virtualNetwork.id(), virtualNetwork);
Set<NetworkId> networkIdSet = tenantIdNetworkIdSetMap.get(tenantId);
if (networkIdSet == null) {
networkIdSet = new HashSet<>();
}
networkIdSet.add(virtualNetwork.id());
tenantIdNetworkIdSetMap.put(tenantId, networkIdSet);
return virtualNetwork;
}
Aggregations