use of org.onosproject.net.TenantId in project onos by opennetworkinglab.
the class TenantListCommand method doExecute.
@Override
protected void doExecute() {
VirtualNetworkAdminService service = get(VirtualNetworkAdminService.class);
List<TenantId> tenants = new ArrayList<>();
tenants.addAll(service.getTenantIds());
Collections.sort(tenants, Comparators.TENANT_ID_COMPARATOR);
tenants.forEach(this::printTenant);
}
use of org.onosproject.net.TenantId 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.net.TenantId in project onos by opennetworkinglab.
the class DefaultVirtualPacketProvider method getMappedVirtualPort.
/**
* Find the corresponding virtual port with the physical port.
*
* @param cp the connect point for the physical network
* @return a virtual port
*/
private VirtualPort getMappedVirtualPort(ConnectPoint cp) {
Set<TenantId> tIds = vnaService.getTenantIds();
Set<VirtualNetwork> vNetworks = new HashSet<>();
tIds.forEach(tid -> vNetworks.addAll(vnaService.getVirtualNetworks(tid)));
for (VirtualNetwork vNet : vNetworks) {
Set<VirtualDevice> vDevices = vnaService.getVirtualDevices(vNet.id());
Set<VirtualPort> vPorts = new HashSet<>();
vDevices.forEach(dev -> vPorts.addAll(vnaService.getVirtualPorts(dev.networkId(), dev.id())));
VirtualPort vPort = vPorts.stream().filter(vp -> vp.realizedBy().equals(cp)).findFirst().orElse(null);
if (vPort != null) {
return vPort;
}
}
return null;
}
use of org.onosproject.net.TenantId in project onos by opennetworkinglab.
the class VirtualNetworkCodec method decode.
@Override
public VirtualNetwork decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
NetworkId nId = NetworkId.networkId(Long.parseLong(extractMember(NETWORK_ID, json)));
TenantId tId = TenantId.tenantId(extractMember(TENANT_ID, json));
return new DefaultVirtualNetwork(nId, tId);
}
use of org.onosproject.net.TenantId in project onos by opennetworkinglab.
the class OFAgentCreateCommand method doExecute.
@Override
protected void doExecute() {
Set<OFController> ctrls = Sets.newHashSet();
for (String strCtrl : strCtrls) {
if (!isValidController(strCtrl)) {
print("Invalid controller %s, ignores it.", strCtrl);
continue;
}
String[] temp = strCtrl.split(":");
ctrls.add(DefaultOFController.of(IpAddress.valueOf(temp[0]), TpPort.tpPort(Integer.valueOf(temp[1]))));
}
VirtualNetworkService virtualNetworkService = get(VirtualNetworkService.class);
TenantId tenantId = virtualNetworkService.getTenantId(NetworkId.networkId(networkId));
checkNotNull(tenantId, "Virtual network %s does not have tenant.", networkId);
OFAgentAdminService adminService = get(OFAgentAdminService.class);
OFAgent ofAgent = DefaultOFAgent.builder().networkId(NetworkId.networkId(networkId)).tenantId(tenantId).controllers(ctrls).state(OFAgent.State.STOPPED).build();
adminService.createAgent(ofAgent);
print("Successfully created OFAgent for network %s, tenant %s", networkId, tenantId);
}
Aggregations