use of org.onosproject.net.EncapsulationType in project onos by opennetworkinglab.
the class ConnectivityIntentCommand method buildConstraints.
/**
* Builds the constraint list for this command based on the command line
* parameters.
*
* @return List of constraint objects describing the constraints requested
*/
protected List<Constraint> buildConstraints() {
final List<Constraint> constraints = new LinkedList<>();
// Check for a bandwidth specification
if (!isNullOrEmpty(bandwidthString)) {
Bandwidth bandwidth;
try {
bandwidth = Bandwidth.bps(Long.parseLong(bandwidthString));
// when the string can't be parsed as long, then try to parse as double
} catch (NumberFormatException e) {
bandwidth = Bandwidth.bps(Double.parseDouble(bandwidthString));
}
constraints.add(new BandwidthConstraint(bandwidth));
}
// Check for partial failure specification
if (partial) {
constraints.add(new PartialFailureConstraint());
}
// Check for encapsulation specification
if (!isNullOrEmpty(encapsulationString)) {
final EncapsulationType encapType = EncapsulationType.valueOf(encapsulationString);
constraints.add(new EncapsulationConstraint(encapType));
}
// Check for hashed path selection
if (hashedPathSelection) {
constraints.add(new HashedPathSelectionConstraint());
}
// Check for domain processing
if (domains) {
constraints.add(DomainConstraint.domain());
}
// Check for a latency specification
if (!isNullOrEmpty(latConstraint)) {
try {
long lat = Long.parseLong(latConstraint);
constraints.add(new LatencyConstraint(Duration.of(lat, ChronoUnit.NANOS)));
} catch (NumberFormatException e) {
double lat = Double.parseDouble(latConstraint);
constraints.add(new LatencyConstraint(Duration.of((long) lat, ChronoUnit.NANOS)));
}
}
return constraints;
}
use of org.onosproject.net.EncapsulationType in project onos by opennetworkinglab.
the class VplsCodec method decode.
@Override
public VplsData decode(ObjectNode json, CodecContext context) {
if (json == null || !json.isObject()) {
return null;
}
List<String> names = new ArrayList<>();
json.findValues(NAME).forEach(jsonNode -> {
names.add(jsonNode.asText());
});
Collection<Interface> interfaceList = new ArrayList<>();
JsonNode interfacesJeson = json.findValue(INTERFACES);
JsonCodec<Interface> interfaceCodec = context.codec(Interface.class);
if (interfacesJeson != null) {
IntStream.range(0, interfacesJeson.size()).forEach(i -> interfaceList.add(interfaceCodec.decode(get(interfacesJeson, i), context)));
}
interfaceList.forEach(interf -> {
names.remove(interf.name());
});
String vplsName = names.get(0);
EncapsulationType encap = json.findValue(ENCAPSULATION_TYPE) == null ? null : EncapsulationType.enumFromString(json.findValue(ENCAPSULATION_TYPE).asText());
VplsData vplsData = VplsData.of(vplsName, encap);
vplsData.addInterfaces(interfaceList);
return vplsData;
}
use of org.onosproject.net.EncapsulationType in project onos by opennetworkinglab.
the class PathIntentCompilerTest method testEncapIngressEgressVlansCompile.
/**
* Tests the compilation behavior of the path intent compiler in case of
* VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}.
* This test includes a selector to match a VLAN at the ingress and a treatment to set VLAN at the egress.
*/
@Test
public void testEncapIngressEgressVlansCompile() {
sut.activate();
List<Intent> compiled = sut.compile(constrainIngressEgressVlanIntent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(3));
FlowRule rule1 = rules.stream().filter(x -> x.deviceId().equals(d1p0.deviceId())).findFirst().get();
verifyIdAndPriority(rule1, d1p0.deviceId());
verifyVlanEncapSelector(rule1.selector(), d1p0, ingressVlan);
VlanId vlanToEncap = verifyVlanEncapTreatment(rule1.treatment(), d1p1, true, false);
FlowRule rule2 = rules.stream().filter(x -> x.deviceId().equals(d2p0.deviceId())).findFirst().get();
verifyIdAndPriority(rule2, d2p0.deviceId());
verifyVlanEncapSelector(rule2.selector(), d2p0, vlanToEncap);
vlanToEncap = verifyVlanEncapTreatment(rule2.treatment(), d2p1, false, false);
FlowRule rule3 = rules.stream().filter(x -> x.deviceId().equals(d3p0.deviceId())).findFirst().get();
verifyIdAndPriority(rule3, d3p1.deviceId());
verifyVlanEncapSelector(rule3.selector(), d3p1, vlanToEncap);
Set<L2ModificationInstruction.ModVlanIdInstruction> vlanMod = rule3.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x).collect(Collectors.toSet());
assertThat(rule3.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanIdInstruction).collect(Collectors.toSet()), hasSize(1));
assertThat(vlanMod.iterator().next().vlanId(), is(egressVlan));
assertThat(rule3.treatment().allInstructions().stream().filter(treat -> treat instanceof L2ModificationInstruction.ModVlanHeaderInstruction).collect(Collectors.toSet()), hasSize(0));
sut.deactivate();
}
use of org.onosproject.net.EncapsulationType in project onos by opennetworkinglab.
the class PathIntentCompilerTest method testVlanEncapCompileEdgeEgressVlan.
/**
* Tests the compilation behavior of the path intent compiler in case of
* VLAN {@link EncapsulationType} encapsulation constraint {@link EncapsulationConstraint}
* and edge communication. No ingress VLAN. Egress VLAN.
*/
@Test
public void testVlanEncapCompileEdgeEgressVlan() {
sut.activate();
List<Intent> compiled = sut.compile(edgeIntentEgressVlan, 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()).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();
}
Aggregations