Search in sources :

Example 6 with TenantId

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);
}
Also used : TenantId(org.onosproject.net.TenantId) ArrayList(java.util.ArrayList) VirtualNetworkAdminService(org.onosproject.incubator.net.virtual.VirtualNetworkAdminService)

Example 7 with TenantId

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));
        }
    });
}
Also used : DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) TenantId(org.onosproject.net.TenantId) DefaultVirtualDevice(org.onosproject.incubator.net.virtual.DefaultVirtualDevice) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) HashSet(java.util.HashSet)

Example 8 with TenantId

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;
}
Also used : VirtualNetwork(org.onosproject.incubator.net.virtual.VirtualNetwork) VirtualPort(org.onosproject.incubator.net.virtual.VirtualPort) TenantId(org.onosproject.net.TenantId) VirtualDevice(org.onosproject.incubator.net.virtual.VirtualDevice) HashSet(java.util.HashSet)

Example 9 with TenantId

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);
}
Also used : TenantId(org.onosproject.net.TenantId) DefaultVirtualNetwork(org.onosproject.incubator.net.virtual.DefaultVirtualNetwork) NetworkId(org.onosproject.incubator.net.virtual.NetworkId)

Example 10 with TenantId

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);
}
Also used : TenantId(org.onosproject.net.TenantId) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) DefaultOFController(org.onosproject.ofagent.impl.DefaultOFController) OFController(org.onosproject.ofagent.api.OFController) DefaultOFAgent(org.onosproject.ofagent.impl.DefaultOFAgent) OFAgent(org.onosproject.ofagent.api.OFAgent) OFAgentAdminService(org.onosproject.ofagent.api.OFAgentAdminService)

Aggregations

TenantId (org.onosproject.net.TenantId)13 VirtualNetwork (org.onosproject.incubator.net.virtual.VirtualNetwork)7 VirtualNetworkAdminService (org.onosproject.incubator.net.virtual.VirtualNetworkAdminService)4 ArrayList (java.util.ArrayList)3 Produces (javax.ws.rs.Produces)3 DefaultVirtualNetwork (org.onosproject.incubator.net.virtual.DefaultVirtualNetwork)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Path (javax.ws.rs.Path)2 UriBuilder (javax.ws.rs.core.UriBuilder)2 StringsCompleter (org.apache.karaf.shell.support.completers.StringsCompleter)2 NetworkId (org.onosproject.incubator.net.virtual.NetworkId)2 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)2 VirtualNetworkService (org.onosproject.incubator.net.virtual.VirtualNetworkService)2 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 Test (org.junit.Test)1 DefaultVirtualDevice (org.onosproject.incubator.net.virtual.DefaultVirtualDevice)1