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!");
}
}
}
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);
}
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);
}
Aggregations