Search in sources :

Example 16 with VirtualNetworkService

use of org.onosproject.incubator.net.virtual.VirtualNetworkService in project onos by opennetworkinglab.

the class VirtualNetworkIntentRemoveCommand method doExecute.

@Override
protected void doExecute() {
    VirtualNetworkService service = get(VirtualNetworkService.class);
    IntentService intentService = service.get(NetworkId.networkId(networkId), IntentService.class);
    CoreService coreService = get(CoreService.class);
    if (purgeAfterRemove || sync) {
        print("Using \"sync\" to remove/purge intents - this may take a while...");
        print("Check \"summary\" to see remove/purge progress.");
    }
    ApplicationId appId = appId();
    if (!isNullOrEmpty(applicationIdString)) {
        appId = coreService.getAppId(applicationIdString);
        if (appId == null) {
            print("Cannot find application Id %s", applicationIdString);
            return;
        }
    }
    if (isNullOrEmpty(keyString)) {
        for (Intent intent : intentService.getIntents()) {
            if (intent.appId().equals(appId)) {
                removeIntent(intentService, intent);
            }
        }
    } else {
        final Key key;
        if (keyString.startsWith("0x")) {
            // The intent uses a LongKey
            keyString = keyString.replaceFirst("0x", "");
            key = Key.of(new BigInteger(keyString, 16).longValue(), appId);
        } else {
            // The intent uses a StringKey
            key = Key.of(keyString, appId);
        }
        Intent intent = intentService.getIntent(key);
        if (intent != null) {
            removeIntent(intentService, intent);
        } else {
            print("Intent not found!");
        }
    }
}
Also used : IntentService(org.onosproject.net.intent.IntentService) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) CoreService(org.onosproject.core.CoreService) BigInteger(java.math.BigInteger) Intent(org.onosproject.net.intent.Intent) ApplicationId(org.onosproject.core.ApplicationId) Key(org.onosproject.net.intent.Key)

Example 17 with VirtualNetworkService

use of org.onosproject.incubator.net.virtual.VirtualNetworkService in project onos by opennetworkinglab.

the class VirtualNetworkPacketRequestCommand method doExecute.

@Override
protected void doExecute() {
    VirtualNetworkService service = get(VirtualNetworkService.class);
    PacketService virtualPacketService = service.get(NetworkId.networkId(networkId), PacketService.class);
    if (command == null) {
        print("Command is not defined");
        return;
    }
    if (command.equals("getRequests")) {
        getRequests(virtualPacketService);
        return;
    }
    TrafficSelector selector = buildTrafficSelector();
    // TODO allow user to specify
    PacketPriority packetPriority = PacketPriority.CONTROL;
    Optional<DeviceId> optionalDeviceId = null;
    if (!isNullOrEmpty(deviceIdString)) {
        optionalDeviceId = Optional.of(DeviceId.deviceId(deviceIdString));
    }
    if (command.equals("requestPackets")) {
        if (optionalDeviceId != null) {
            virtualPacketService.requestPackets(selector, packetPriority, appId(), optionalDeviceId);
        } else {
            virtualPacketService.requestPackets(selector, packetPriority, appId());
        }
        print("Virtual packet requested:\n%s", selector);
        return;
    }
    if (command.equals("cancelPackets")) {
        if (optionalDeviceId != null) {
            virtualPacketService.cancelPackets(selector, packetPriority, appId(), optionalDeviceId);
        } else {
            virtualPacketService.cancelPackets(selector, packetPriority, appId());
        }
        print("Virtual packet cancelled:\n%s", selector);
        return;
    }
    print("Unsupported command %s", command);
}
Also used : PacketPriority(org.onosproject.net.packet.PacketPriority) PacketService(org.onosproject.net.packet.PacketService) VirtualNetworkService(org.onosproject.incubator.net.virtual.VirtualNetworkService) DeviceId(org.onosproject.net.DeviceId) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector)

Example 18 with VirtualNetworkService

use of org.onosproject.incubator.net.virtual.VirtualNetworkService 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

VirtualNetworkService (org.onosproject.incubator.net.virtual.VirtualNetworkService)18 ArrayList (java.util.ArrayList)9 VirtualDevice (org.onosproject.incubator.net.virtual.VirtualDevice)4 VirtualPort (org.onosproject.incubator.net.virtual.VirtualPort)4 CoreService (org.onosproject.core.CoreService)2 VirtualHost (org.onosproject.incubator.net.virtual.VirtualHost)2 ConnectPoint (org.onosproject.net.ConnectPoint)2 DeviceId (org.onosproject.net.DeviceId)2 TenantId (org.onosproject.net.TenantId)2 TrafficSelector (org.onosproject.net.flow.TrafficSelector)2 Intent (org.onosproject.net.intent.Intent)2 IntentService (org.onosproject.net.intent.IntentService)2 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 BigInteger (java.math.BigInteger)1 List (java.util.List)1 StringFilter (org.onlab.util.StringFilter)1 ApplicationId (org.onosproject.core.ApplicationId)1 DefaultVirtualPort (org.onosproject.incubator.net.virtual.DefaultVirtualPort)1 NetworkId (org.onosproject.incubator.net.virtual.NetworkId)1 VirtualLink (org.onosproject.incubator.net.virtual.VirtualLink)1