use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class LinkManagerTest method addLink.
private Link addLink(DeviceId sd, PortNumber sp, DeviceId dd, PortNumber dp, Link.Type type) {
providerService.linkDetected(new DefaultLinkDescription(cp(sd, sp), cp(dd, dp), type));
Link link = listener.events.get(0).subject();
validateEvents(LINK_ADDED);
return link;
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class PathIntentCompilerTest method testVlanEncapCompileSingleHopDirectEgressVlan.
/**
* Tests the compilation behavior of the path intent compiler in case of
* VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
* and single-hop-direct-link scenario. No ingress VLAN. Egress VLAN.
*/
@Test
public void testVlanEncapCompileSingleHopDirectEgressVlan() {
sut.activate();
List<Intent> compiled = sut.compile(singleHopDirectIntentEgressVlan, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(1));
FlowRule rule = rules.stream().filter(x -> x.deviceId().equals(d2p4.deviceId())).findFirst().get();
verifyIdAndPriority(rule, d2p4.deviceId());
assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p4.port()).build()));
assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(egressVlan).setOutput(d2p5.port()).build()));
Set<L2ModificationInstruction.ModVlanIdInstruction> vlanMod = rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x).collect(Collectors.toSet());
assertThat(rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).collect(Collectors.toSet()), hasSize(1));
assertThat(vlanMod.iterator().next().vlanId(), is(egressVlan));
assertThat(rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanHeaderInstruction).collect(Collectors.toSet()), hasSize(0));
sut.deactivate();
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class PathIntentCompilerTest method testVlanEncapCompileEdgeVlan.
/**
* Tests the compilation behavior of the path intent compiler in case of
* VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
* and edge communication. Ingress VLAN. Egress VLAN.
*/
@Test
public void testVlanEncapCompileEdgeVlan() {
sut.activate();
List<Intent> compiled = sut.compile(edgeIntentVlan, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(1));
FlowRule rule = rules.stream().filter(x -> x.deviceId().equals(d1p2.deviceId())).findFirst().get();
verifyIdAndPriority(rule, d1p2.deviceId());
assertThat(rule.selector(), is(DefaultTrafficSelector.builder().matchInPort(d1p2.port()).matchVlanId(ingressVlan).build()));
assertThat(rule.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(egressVlan).setOutput(d1p3.port()).build()));
Set<L2ModificationInstruction.ModVlanIdInstruction> vlanMod = rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x).collect(Collectors.toSet());
assertThat(rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).collect(Collectors.toSet()), hasSize(1));
assertThat(vlanMod.iterator().next().vlanId(), is(egressVlan));
assertThat(rule.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanHeaderInstruction).collect(Collectors.toSet()), hasSize(0));
sut.deactivate();
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class OpticalIntentsWebResource method getIntents.
/**
* Get the optical intents on the network.
*
* @return 200 OK
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getIntents() {
DeviceService deviceService = get(DeviceService.class);
IntentService intentService = get(IntentService.class);
Iterator intentItr = intentService.getIntents().iterator();
ArrayNode arrayFlows = mapper().createArrayNode();
while (intentItr.hasNext()) {
Intent intent = (Intent) intentItr.next();
if (intent instanceof OpticalConnectivityIntent) {
OpticalConnectivityIntent opticalConnectivityIntent = (OpticalConnectivityIntent) intent;
Device srcDevice = deviceService.getDevice(opticalConnectivityIntent.getSrc().deviceId());
Device dstDevice = deviceService.getDevice(opticalConnectivityIntent.getDst().deviceId());
String srcDeviceName = srcDevice.annotations().value(AnnotationKeys.NAME);
String dstDeviceName = dstDevice.annotations().value(AnnotationKeys.NAME);
ObjectNode objectNode = mapper().createObjectNode();
objectNode.put("intent id", opticalConnectivityIntent.id().toString());
objectNode.put("app id", opticalConnectivityIntent.appId().name());
objectNode.put("state", intentService.getIntentState(opticalConnectivityIntent.key()).toString());
objectNode.put("src", opticalConnectivityIntent.getSrc().toString());
objectNode.put("dst", opticalConnectivityIntent.getDst().toString());
objectNode.put("srcName", srcDeviceName);
objectNode.put("dstName", dstDeviceName);
// Only for INSTALLED intents
if (intentService.getIntentState(intent.key()) == IntentState.INSTALLED) {
// Retrieve associated FlowRuleIntent
FlowRuleIntent installableIntent = (FlowRuleIntent) intentService.getInstallableIntents(opticalConnectivityIntent.key()).stream().filter(FlowRuleIntent.class::isInstance).findFirst().orElse(null);
// TODO store utilized ochSignal in the intent resources
if (installableIntent != null) {
OchSignal signal = installableIntent.flowRules().stream().filter(r -> r.selector().criteria().size() == NUM_CRITERIA_OPTICAL_CONNECTIVIY_RULE).map(r -> ((OchSignalCriterion) r.selector().getCriterion(Criterion.Type.OCH_SIGID)).lambda()).findFirst().orElse(null);
objectNode.put("ochSignal", signal.toString());
objectNode.put("centralFreq", signal.centralFrequency().asTHz() + " THz");
}
// Retrieve path and print it to REST
if (installableIntent != null) {
String path = installableIntent.resources().stream().filter(Link.class::isInstance).map(Link.class::cast).map(r -> deviceService.getDevice(r.src().deviceId())).map(r -> r.annotations().value(AnnotationKeys.NAME)).collect(Collectors.joining(" -> "));
List<Link> pathLinks = installableIntent.resources().stream().filter(Link.class::isInstance).map(Link.class::cast).collect(Collectors.toList());
DefaultPath defaultPath = new DefaultPath(PROVIDER_ID, pathLinks, new ScalarWeight(1));
objectNode.put("path", defaultPath.toString());
objectNode.put("pathName", path + " -> " + dstDeviceName);
}
}
arrayFlows.add(objectNode);
}
}
ObjectNode root = this.mapper().createObjectNode().putPOJO("Intents", arrayFlows);
return ok(root).build();
}
use of org.onosproject.net.Link in project onos by opennetworkinglab.
the class OpticalPathIntentCompiler method createRules.
/**
* Create rules for the forward path of the intent.
*
* @param intent the intent
* @return list of flow rules
*/
private List<FlowRule> createRules(OpticalPathIntent intent) {
TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
selectorBuilder.matchInPort(intent.src().port());
List<FlowRule> rules = new LinkedList<>();
/*
* especial case for 0 hop when srcDeviceId = dstDeviceId
* and path contain only one fake default path.
*/
if (intent.src().deviceId().equals(intent.dst().deviceId()) && intent.path().links().size() == 1) {
log.debug("handling 0 hop case for intent {}", intent);
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
if (!isTransparent(intent.src().deviceId())) {
treatmentBuilder.add(Instructions.modL0Lambda(intent.lambda()));
}
treatmentBuilder.setOutput(intent.dst().port());
FlowRule rule = DefaultFlowRule.builder().forDevice(intent.src().deviceId()).withSelector(selectorBuilder.build()).withTreatment(treatmentBuilder.build()).withPriority(intent.priority()).fromApp(appId).makePermanent().build();
rules.add(rule);
return rules;
}
ConnectPoint current = intent.src();
for (Link link : intent.path().links()) {
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
if (!isTransparent(current.deviceId())) {
treatmentBuilder.add(Instructions.modL0Lambda(intent.lambda()));
}
treatmentBuilder.setOutput(link.src().port());
FlowRule rule = DefaultFlowRule.builder().forDevice(current.deviceId()).withSelector(selectorBuilder.build()).withTreatment(treatmentBuilder.build()).withPriority(intent.priority()).fromApp(appId).makePermanent().build();
selectorBuilder = DefaultTrafficSelector.builder();
if (!isNoFlowRule(current.deviceId())) {
rules.add(rule);
}
current = link.dst();
selectorBuilder.matchInPort(link.dst().port());
if (!isTransparent(current.deviceId())) {
selectorBuilder.add(Criteria.matchLambda(intent.lambda()));
selectorBuilder.add(Criteria.matchOchSignalType(intent.signalType()));
}
}
// Build the egress ROADM rule
TrafficTreatment.Builder treatmentLast = DefaultTrafficTreatment.builder();
treatmentLast.setOutput(intent.dst().port());
FlowRule rule = new DefaultFlowRule.Builder().forDevice(intent.dst().deviceId()).withSelector(selectorBuilder.build()).withTreatment(treatmentLast.build()).withPriority(intent.priority()).fromApp(appId).makePermanent().build();
if (!isNoFlowRule(intent.dst().deviceId())) {
rules.add(rule);
}
return rules;
}
Aggregations