use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class AllocationsCommand method doExecute.
@Override
protected void doExecute() {
deviceService = get(DeviceService.class);
resourceService = get(ResourceService.class);
if (typeStrings != null) {
typesToPrint = new HashSet<>(Arrays.asList(typeStrings));
} else {
typesToPrint = Collections.emptySet();
}
if (intentStrings != null) {
intentsToPrint = new HashSet<>(Arrays.asList(intentStrings));
} else {
intentsToPrint = Collections.emptySet();
}
if (deviceIdStr != null && portNumberStr != null) {
DeviceId deviceId = deviceId(deviceIdStr);
PortNumber portNumber = PortNumber.fromString(portNumberStr);
printAllocation(deviceId, portNumber, 0);
} else if (deviceIdStr != null) {
DeviceId deviceId = deviceId(deviceIdStr);
printAllocation(deviceId, 0);
} else {
printAllocation();
}
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class AllocationsCommand method printAllocation.
private void printAllocation(DeviceId did, PortNumber num, int level) {
if (level == 0) {
// print DeviceId when Port was directly specified.
print("%s", did);
}
DiscreteResourceId resourceId = Resources.discrete(did, num).id();
List<String> portConsumers = resourceService.getResourceAllocations(resourceId).stream().filter(this::isSubjectToPrint).map(ResourceAllocation::consumerId).map(AllocationsCommand::asVerboseString).collect(Collectors.toList());
if (portConsumers.isEmpty()) {
print("%s%s", Strings.repeat(" ", level), asVerboseString(num));
} else {
print("%s%s allocated by %s", Strings.repeat(" ", level), asVerboseString(num), portConsumers);
}
// FIXME: This workaround induces a lot of distributed store access.
// ResourceService should have an API to get all allocations under a parent resource.
Set<Class<?>> subResourceTypes = ImmutableSet.<Class<?>>builder().add(OchSignal.class).add(VlanId.class).add(MplsLabel.class).add(Bandwidth.class).add(TributarySlot.class).build();
for (Class<?> t : subResourceTypes) {
resourceService.getResourceAllocations(resourceId, t).stream().filter(a -> isSubjectToPrint(a)).forEach(a -> print("%s%s allocated by %s", Strings.repeat(" ", level + 1), a.resource().valueAs(Object.class).orElse(""), asVerboseString(a.consumerId())));
}
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class ConnectivityIntentCommand method buildTrafficTreatment.
/**
* Generates a traffic treatment for this intent based on command line
* arguments presented to the command.
*
* @return traffic treatment
*/
protected TrafficTreatment buildTrafficTreatment() {
final TrafficTreatment.Builder treatmentBuilder = builder();
boolean emptyTreatment = true;
if (!isNullOrEmpty(setEthSrcString)) {
treatmentBuilder.setEthSrc(MacAddress.valueOf(setEthSrcString));
emptyTreatment = false;
}
if (!isNullOrEmpty(setEthDstString)) {
treatmentBuilder.setEthDst(MacAddress.valueOf(setEthDstString));
emptyTreatment = false;
}
if (!isNullOrEmpty(setIpSrcString)) {
treatmentBuilder.setIpSrc(IpAddress.valueOf(setIpSrcString));
emptyTreatment = false;
}
if (!isNullOrEmpty(setIpDstString)) {
treatmentBuilder.setIpDst(IpAddress.valueOf(setIpDstString));
emptyTreatment = false;
}
if (!isNullOrEmpty(setVlan)) {
treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(setVlan)));
emptyTreatment = false;
}
if (popVlan) {
treatmentBuilder.popVlan();
emptyTreatment = false;
}
if (!isNullOrEmpty(pushVlan)) {
treatmentBuilder.pushVlan();
treatmentBuilder.setVlanId(VlanId.vlanId(Short.parseShort(pushVlan)));
emptyTreatment = false;
}
if (!isNullOrEmpty(setQueue)) {
// OpenFlow 1.0 notation (for ENQUEUE): <port>/<queue>
if (setQueue.contains("/")) {
String[] queueConfig = setQueue.split("/");
PortNumber port = PortNumber.portNumber(Long.parseLong(queueConfig[0]));
long queueId = Long.parseLong(queueConfig[1]);
treatmentBuilder.setQueue(queueId, port);
} else {
treatmentBuilder.setQueue(Long.parseLong(setQueue));
}
emptyTreatment = false;
}
if (emptyTreatment) {
return DefaultTrafficTreatment.emptyTreatment();
} else {
return treatmentBuilder.build();
}
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class DevicePortStateCommand method doExecute.
@Override
protected void doExecute() {
DeviceService deviceService = get(DeviceService.class);
DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
Device dev = deviceService.getDevice(DeviceId.deviceId(uri));
if (dev == null) {
print(" %s", "Device does not exist");
return;
}
PortNumber pnum = PortNumber.fromString(portNumber);
Port p = deviceService.getPort(dev.id(), pnum);
if (p == null) {
print(" %s", "Port does not exist");
return;
}
if ("enable".equals(portState)) {
deviceAdminService.changePortState(dev.id(), p.number(), true);
} else if ("disable".equals(portState)) {
deviceAdminService.changePortState(dev.id(), p.number(), false);
} else {
print(" %s", "State must be enable or disable");
}
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class IntentCycleCommand method doExecute.
@Override
protected void doExecute() {
service = get(IntentService.class);
DeviceId ingressDeviceId = deviceId(getDeviceId(ingressDeviceString));
PortNumber ingressPortNumber = portNumber(getPortNumber(ingressDeviceString));
ConnectPoint ingress = new ConnectPoint(ingressDeviceId, ingressPortNumber);
DeviceId egressDeviceId = deviceId(getDeviceId(egressDeviceString));
PortNumber egressPortNumber = portNumber(getPortNumber(egressDeviceString));
ConnectPoint egress = new ConnectPoint(egressDeviceId, egressPortNumber);
count = Integer.parseInt(numberOfIntents);
keyOffset = (keyOffsetStr != null) ? Integer.parseInt(keyOffsetStr) : 1;
service.addListener(this);
List<Intent> operations = generateIntents(ingress, egress);
add = true;
start = System.currentTimeMillis();
while (start + 10000 > System.currentTimeMillis()) {
submitIntents(operations);
}
delay(5000);
printResults();
add = false;
submitIntents(operations);
service.removeListener(this);
}
Aggregations