use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class TapiFlowRuleProgrammable method createConnectivityRequest.
ByteArrayOutputStream createConnectivityRequest(String uuid, FlowRule rule) {
/*
{
"tapi-connectivity:connectivity-service":[
{
"uuid":"ffb006d4-349e-4d2f-817e-0906c88458d0",
"service-layer":"PHOTONIC_MEDIA",
"service-type":"POINT_TO_POINT_CONNECTIVITY",
"end-point":[
{
"local-id":"1",
"layer-protocol-name":"PHOTONIC_MEDIA",
"layer-protocol-qualifier":"tapi-photonic-media:PHOTONIC_LAYER_QUALIFIER_NMC",
"service-interface-point":{
"service-interface-point-uuid":"0923962e-b83f-4702-9b16-a1a0db0dc1f9"
}
},
{
"local-id":"2",
"layer-protocol-name":"PHOTONIC_MEDIA",
"layer-protocol-qualifier":"tapi-photonic-media:PHOTONIC_LAYER_QUALIFIER_NMC",
"service-interface-point":{
"service-interface-point-uuid":"76be95de-5769-4e5d-b65e-62cb6c39cf6b "
}
}
]
}
]
}
*/
DeviceService deviceService = handler().get(DeviceService.class);
PortCriterion inputPortCriterion = (PortCriterion) checkNotNull(rule.selector().getCriterion(Criterion.Type.IN_PORT));
String inputPortUuid = deviceService.getPort(rule.deviceId(), inputPortCriterion.port()).annotations().value(TapiDeviceHelper.UUID);
Instructions.OutputInstruction outInstruction = (Instructions.OutputInstruction) checkNotNull(rule.treatment().allInstructions().stream().filter(instr -> instr.type().equals(Instruction.Type.OUTPUT)).findFirst().orElse(null));
String outputPortUuid = deviceService.getPort(rule.deviceId(), outInstruction.port()).annotations().value(TapiDeviceHelper.UUID);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
JsonGenerator generator = getJsonGenerator(stream);
generator.writeStartObject();
generator.writeArrayFieldStart(TAPI_CONNECTIVITY_CONNECTIVITY_SERVICE);
generator.writeStartObject();
generator.writeStringField(TapiDeviceHelper.UUID, uuid);
generator.writeStringField(SERVICE_LAYER, PHOTONIC_MEDIA);
generator.writeStringField(SERVICE_TYPE, POINT_TO_POINT_CONNECTIVITY);
generator.writeArrayFieldStart(END_POINT);
// ADVA OLS requires these to be 1,2 for every connection
addEndPoint(generator, inputPortUuid, 1);
addEndPoint(generator, outputPortUuid, 2);
generator.writeEndArray();
generator.writeEndObject();
generator.writeEndArray();
generator.writeEndObject();
generator.close();
return stream;
} catch (IOException e) {
log.error("Cant' create json", e);
}
return stream;
}
use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class LinkCollectionEncapIntentCompilerTest method testCoLocatedFilteredPointsTrivialForMp.
/**
* We test the proper compilation of mp2sp with trivial selector,
* trivial treatment, vlan encapsulation and co-located
* filtered ingress/egress points.
*/
@Test
public void testCoLocatedFilteredPointsTrivialForMp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).links(linksForMp2SpCoLoc).constraints(constraintsForVlan).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, mpls100Selector), new FilteredConnectPoint(d2p10, mpls200Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11, mpls69Selector))).build();
sut.activate();
LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(3));
Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS1, hasSize(2));
FlowRule ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p10.port());
}).findFirst().get();
assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(mpls100Selector).matchInPort(d1p10.port()).build()));
assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().setMpls(((MplsCriterion) mpls69Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d1p11.port()).build()));
ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p0.port());
}).findFirst().get();
assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId(LABEL)).matchInPort(d1p0.port()).build()));
assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().popVlan().pushMpls().setMpls(((MplsCriterion) mpls69Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d1p11.port()).build()));
Collection<FlowRule> rulesS2 = rules.stream().filter(rule -> rule.deviceId().equals(d2p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS2, hasSize(1));
FlowRule ruleS2 = rulesS2.iterator().next();
assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder(mpls200Selector).matchInPort(d2p10.port()).build()));
assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().popMpls(IPV4.ethType()).pushVlan().setVlanId(VlanId.vlanId(LABEL)).setOutput(d2p0.port()).build()));
sut.deactivate();
}
use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class LinkCollectionEncapIntentCompilerTest method testVlanEncapsulationForMp.
/**
* We test the proper compilation of mp2Sp1 with the VLAN
* encapsulation, trivial selector.
*/
@Test
public void testVlanEncapsulationForMp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).constraints(constraintsForVlan).links(linksForMp2Sp).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10), new FilteredConnectPoint(d1p11), new FilteredConnectPoint(d2p10))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10))).build();
sut.activate();
/*
* We use the FIRST_FIT to simplify tests.
*/
LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(5));
Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS1, hasSize(2));
FlowRule ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p10.port());
}).findFirst().get();
assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(intent.selector()).matchInPort(d1p10.port()).build()));
assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().pushVlan().setVlanId(VlanId.vlanId(LABEL)).setOutput(d1p0.port()).build()));
ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p11.port());
}).findFirst().get();
assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(intent.selector()).matchInPort(d1p11.port()).build()));
assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().pushVlan().setVlanId(VlanId.vlanId(LABEL)).setOutput(d1p0.port()).build()));
Collection<FlowRule> rulesS2 = rules.stream().filter(rule -> rule.deviceId().equals(d2p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS2, hasSize(2));
FlowRule ruleS2 = rulesS2.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d2p10.port());
}).findFirst().get();
assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder(intent.selector()).matchInPort(d2p10.port()).build()));
assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().pushVlan().setVlanId(VlanId.vlanId(LABEL)).setOutput(d2p1.port()).build()));
ruleS2 = rulesS2.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d2p0.port());
}).findFirst().get();
assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p0.port()).matchVlanId(VlanId.vlanId(LABEL)).build()));
assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId(LABEL)).setOutput(d2p1.port()).build()));
Collection<FlowRule> rulesS3 = rules.stream().filter(rule -> rule.deviceId().equals(d3p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS3, hasSize(1));
FlowRule ruleS3 = rulesS3.iterator().next();
assertThat(ruleS3.selector(), is(DefaultTrafficSelector.builder().matchInPort(d3p0.port()).matchVlanId(VlanId.vlanId(LABEL)).build()));
assertThat(ruleS3.treatment(), is(DefaultTrafficTreatment.builder().popVlan().setOutput(d3p10.port()).build()));
sut.deactivate();
}
use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class LinkCollectionEncapIntentCompilerTest method testMplsEncapsulationDifferentFilterForMp.
/**
* We test the proper compilation of mp2sp with the MPLS
* encapsulation and filtered selectors of different type.
*/
@Test
public void testMplsEncapsulationDifferentFilterForMp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).constraints(constraintsForMPLS).links(linksForMp2Sp).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d3p10, mpls100Selector))).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, vlan100Selector), new FilteredConnectPoint(d1p11, mpls200Selector), new FilteredConnectPoint(d2p10, vlan200Selector))).build();
sut.activate();
LinkCollectionCompiler.labelAllocator.setLabelSelection(LABEL_SELECTION);
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(5));
Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS1, hasSize(2));
FlowRule ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p10.port());
}).findFirst().get();
assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(vlan100Selector).matchInPort(d1p10.port()).build()));
assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().popVlan().pushMpls().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d1p0.port()).build()));
ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p11.port());
}).findFirst().get();
assertThat(ruleS1.selector(), is(DefaultTrafficSelector.builder(mpls200Selector).matchInPort(d1p11.port()).build()));
assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d1p0.port()).build()));
Collection<FlowRule> rulesS2 = rules.stream().filter(rule -> rule.deviceId().equals(d2p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS2, hasSize(2));
FlowRule ruleS2 = rulesS2.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d2p10.port());
}).findFirst().get();
assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder(vlan200Selector).matchInPort(d2p10.port()).build()));
assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().popVlan().pushMpls().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d2p1.port()).build()));
ruleS2 = rulesS2.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d2p0.port());
}).findFirst().get();
assertThat(ruleS2.selector(), is(DefaultTrafficSelector.builder().matchInPort(d2p0.port()).matchMplsLabel(MplsLabel.mplsLabel(LABEL)).matchEthType(Ethernet.MPLS_UNICAST).build()));
assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setMpls(MplsLabel.mplsLabel(LABEL)).setOutput(d2p1.port()).build()));
Collection<FlowRule> rulesS3 = rules.stream().filter(rule -> rule.deviceId().equals(d3p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS3, hasSize(1));
FlowRule ruleS3 = rulesS3.iterator().next();
assertThat(ruleS3.selector(), is(DefaultTrafficSelector.builder().matchInPort(d3p0.port()).matchMplsLabel(MplsLabel.mplsLabel(LABEL)).matchEthType(Ethernet.MPLS_UNICAST).build()));
assertThat(ruleS3.treatment(), is(DefaultTrafficTreatment.builder().setMpls(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label()).setOutput(d3p10.port()).build()));
sut.deactivate();
}
use of org.onosproject.net.flow.criteria.PortCriterion in project onos by opennetworkinglab.
the class LinkCollectionIntentCompilerTest method singleHopTestForMp.
/**
* We test the proper compilation of mp2sp with
* trivial selector, trivial treatment and 1 hop.
*/
@Test
public void singleHopTestForMp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(selector).treatment(treatment).links(ImmutableSet.of()).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10), new FilteredConnectPoint(d1p11))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p0))).build();
sut.activate();
List<Intent> compiled = sut.compile(intent, Collections.emptyList());
assertThat(compiled, hasSize(1));
Collection<FlowRule> rules = ((FlowRuleIntent) compiled.get(0)).flowRules();
assertThat(rules, hasSize(2));
Collection<FlowRule> rulesS1 = rules.stream().filter(rule -> rule.deviceId().equals(d1p0.deviceId())).collect(Collectors.toSet());
assertThat(rulesS1, hasSize(2));
FlowRule ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p10.port());
}).findFirst().get();
assertThat(ruleS1.selector(), Is.is(DefaultTrafficSelector.builder().matchInPort(d1p10.port()).build()));
assertThat(ruleS1.treatment(), Is.is(DefaultTrafficTreatment.builder().setOutput(d1p0.port()).build()));
ruleS1 = rulesS1.stream().filter(rule -> {
PortCriterion inPort = (PortCriterion) rule.selector().getCriterion(IN_PORT);
return inPort.port().equals(d1p11.port());
}).findFirst().get();
assertThat(ruleS1.selector(), Is.is(DefaultTrafficSelector.builder().matchInPort(d1p11.port()).build()));
assertThat(ruleS1.treatment(), Is.is(DefaultTrafficTreatment.builder().setOutput(d1p0.port()).build()));
sut.deactivate();
}
Aggregations