use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class LinkCollectionIntentFlowObjectiveCompiler method buildFilteringObjective.
private FilteringObjective buildFilteringObjective(LinkCollectionIntent intent, TrafficSelector selector, DeviceId deviceId, PortNumber inPort) {
FilteringObjective.Builder builder = DefaultFilteringObjective.builder();
builder.fromApp(appId).permit().makePermanent().withPriority(intent.priority());
Criterion inPortCriterion = selector.getCriterion(Criterion.Type.IN_PORT);
if (inPortCriterion != null) {
builder.withKey(inPortCriterion);
}
FilteredConnectPoint ingressPoint = intent.filteredIngressPoints().stream().filter(fcp -> fcp.connectPoint().equals(new ConnectPoint(deviceId, inPort))).filter(fcp -> selector.criteria().containsAll(fcp.trafficSelector().criteria())).findFirst().orElse(null);
AtomicBoolean emptyCondition = new AtomicBoolean(true);
if (ingressPoint != null) {
// ingress point, use criterion of it
ingressPoint.trafficSelector().criteria().forEach(criterion -> {
builder.addCondition(criterion);
emptyCondition.set(false);
});
if (emptyCondition.get()) {
return null;
}
return builder.add();
}
Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent);
if (encapConstraint.isPresent() && !encapConstraint.get().encapType().equals(EncapsulationType.NONE)) {
// encapsulation enabled, use encapsulation label and tag.
EncapsulationConstraint encap = encapConstraint.get();
switch(encap.encapType()) {
case VLAN:
builder.addCondition(selector.getCriterion(Criterion.Type.VLAN_VID));
emptyCondition.set(false);
break;
case MPLS:
builder.addCondition(selector.getCriterion(Criterion.Type.MPLS_LABEL));
emptyCondition.set(false);
break;
default:
log.warn("No filtering rule found because of unknown encapsulation type.");
break;
}
} else {
// encapsulation not enabled, check if the treatment applied to the ingress or not
if (intent.applyTreatmentOnEgress()) {
// filtering criterion will be changed on egress point, use
// criterion of ingress point
ingressPoint = intent.filteredIngressPoints().stream().findFirst().orElse(null);
if (ingressPoint == null) {
log.warn("No filtering rule found because no ingress point in the Intent");
} else {
ingressPoint.trafficSelector().criteria().stream().filter(criterion -> !criterion.type().equals(Criterion.Type.IN_PORT)).forEach(criterion -> {
builder.addCondition(criterion);
emptyCondition.set(false);
});
}
} else {
// filtering criterion will be changed on ingress point, use
// criterion of egress point
FilteredConnectPoint egressPoint = intent.filteredEgressPoints().stream().findFirst().orElse(null);
if (egressPoint == null) {
log.warn("No filtering rule found because no egress point in the Intent");
} else {
egressPoint.trafficSelector().criteria().stream().filter(criterion -> !criterion.type().equals(Criterion.Type.IN_PORT)).forEach(criterion -> {
builder.addCondition(criterion);
emptyCondition.set(false);
});
}
}
}
if (emptyCondition.get()) {
return null;
}
return builder.add();
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class PointToPointIntentCompiler method createProtectedIntent.
// FIXME: Compatibility with EncapsulationConstraint
private List<Intent> createProtectedIntent(ConnectPoint ingressPoint, ConnectPoint egressPoint, PointToPointIntent intent, List<Intent> installable) {
log.trace("createProtectedIntent");
DisjointPath path = getDisjointPath(intent, ingressPoint.deviceId(), egressPoint.deviceId());
List<Intent> reusableIntents = null;
if (installable != null) {
reusableIntents = filterInvalidSubIntents(installable, intent);
if (reusableIntents.size() == installable.size()) {
// all old paths are still viable
return installable;
}
}
List<Intent> intentList = new ArrayList<>();
// primary path intent
List<Link> links = new ArrayList<>();
links.addAll(path.links());
links.add(createEdgeLink(egressPoint, false));
// backup path intent
List<Link> backupLinks = new ArrayList<>();
backupLinks.addAll(path.backup().links());
backupLinks.add(createEdgeLink(egressPoint, false));
/*
* One of the old paths is still entirely intact. This old path has
* already been made primary, so we must add a backup path intent
* and modify the failover group treatment accordingly.
*/
if (reusableIntents != null && reusableIntents.size() > 1) {
/*
* Ensures that the egress port on source device is different than
* that of existing path so that failover group will be useful
* (would not be useful if both output ports in group bucket were
* the same). Does not necessarily ensure that the new backup path
* is entirely disjoint from the old path.
*/
PortNumber primaryPort = getPrimaryPort(intent);
if (primaryPort != null && !links.get(0).src().port().equals(primaryPort)) {
reusableIntents.add(createPathIntent(new DefaultPath(PID, links, path.weight(), path.annotations()), intent, PathIntent.ProtectionType.BACKUP));
updateFailoverGroup(intent, links);
return reusableIntents;
} else {
reusableIntents.add(createPathIntent(new DefaultPath(PID, backupLinks, path.backup().weight(), path.backup().annotations()), intent, PathIntent.ProtectionType.BACKUP));
updateFailoverGroup(intent, backupLinks);
return reusableIntents;
}
}
intentList.add(createPathIntent(new DefaultPath(PID, links, path.weight(), path.annotations()), intent, PathIntent.ProtectionType.PRIMARY));
intentList.add(createPathIntent(new DefaultPath(PID, backupLinks, path.backup().weight(), path.backup().annotations()), intent, PathIntent.ProtectionType.BACKUP));
// add contents appropriately.
if (groupService.getGroup(ingressPoint.deviceId(), makeGroupKey(intent.id())) == null) {
// manufactured fast failover flow rule intent
createFailoverTreatmentGroup(path.links(), path.backup().links(), intent);
FlowRuleIntent frIntent = new FlowRuleIntent(intent.appId(), intent.key(), createFailoverFlowRules(intent), asList(ingressPoint.deviceId()), PathIntent.ProtectionType.FAILOVER, intent.resourceGroup());
intentList.add(frIntent);
} else {
updateFailoverGroup(intent, links);
updateFailoverGroup(intent, backupLinks);
}
return intentList;
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class DeviceInjectionConfigMonitor method injectDevice.
private void injectDevice(DeviceId did) {
Optional<BasicDeviceConfig> basic = Optional.ofNullable(netcfgService.getConfig(did, BasicDeviceConfig.class));
Optional<DeviceDescriptionDiscovery> discovery = basic.map(BasicDeviceConfig::driver).map(driverService::getDriver).filter(drvr -> drvr.hasBehaviour(DeviceDescriptionDiscovery.class)).map(drvr -> drvr.createBehaviour(new DefaultDriverHandler(new DefaultDriverData(drvr, did)), DeviceDescriptionDiscovery.class));
if (discovery.isPresent()) {
providerService.deviceConnected(did, discovery.get().discoverDeviceDetails());
providerService.updatePorts(did, discovery.get().discoverPortDetails());
} else {
String unk = "UNKNOWN";
DefaultDeviceDescription desc = new DefaultDeviceDescription(did.uri(), basic.map(BasicDeviceConfig::type).orElse(Type.SWITCH), basic.map(BasicDeviceConfig::manufacturer).orElse(unk), basic.map(BasicDeviceConfig::hwVersion).orElse(unk), basic.map(BasicDeviceConfig::swVersion).orElse(unk), basic.map(BasicDeviceConfig::serial).orElse(unk), new ChassisId(), true);
providerService.deviceConnected(did, desc);
Optional<DeviceInjectionConfig> inject = Optional.ofNullable(netcfgService.getConfig(did, DeviceInjectionConfig.class));
String ports = inject.map(DeviceInjectionConfig::ports).orElse("0");
int numPorts = Integer.parseInt(ports);
List<PortDescription> portDescs = new ArrayList<>(numPorts);
for (int i = 1; i <= numPorts; ++i) {
// TODO inject port details if something like BasicPortConfig was created
PortNumber number = portNumber(i);
boolean isEnabled = true;
portDescs.add(DefaultPortDescription.builder().withPortNumber(number).isEnabled(isEnabled).build());
}
providerService.updatePorts(did, portDescs);
}
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class OplinkOpticalDeviceDescription method parsePort.
private PortDescription parsePort(HierarchicalConfiguration cfg) {
PortNumber portNumber = PortNumber.portNumber(cfg.getLong(KEY_PORTID));
HierarchicalConfiguration portInfo = cfg.configurationAt(KEY_PORT);
DefaultAnnotations annotations = DefaultAnnotations.builder().set(AnnotationKeys.PORT_NAME, portInfo.getString(KEY_PORTNAME)).set(PORT_DIRECTION, portInfo.getString(KEY_PORTDIRECT)).build();
return omsPortDescription(portNumber, true, START_CENTER_FREQ, STOP_CENTER_FREQ, CHANNEL_SPACING.frequency(), annotations);
}
use of org.onosproject.net.PortNumber in project onos by opennetworkinglab.
the class OplinkOpticalProtectionSwitchConfig method buildProtectedTransportEndpointState.
private ProtectedTransportEndpointState buildProtectedTransportEndpointState() {
// First, get active port from device.
PortNumber activePort = acquireActivePort();
// Build all endpoint state with port working attribute.
List<TransportEndpointState> states = new ArrayList<>();
states.add(buildTransportEndpointState(data().deviceId(), PORT_PRIMARY, activePort));
states.add(buildTransportEndpointState(data().deviceId(), PORT_SECONDARY, activePort));
return ProtectedTransportEndpointState.builder().withPathStates(states).withDescription(buildProtectedTransportEndpointDescription()).withActivePathIndex(getActiveIndex(states, activePort)).build();
}
Aggregations