use of org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction in project onos by opennetworkinglab.
the class LinkCollectionEncapIntentCompilerTest method testCoLocatedDifferentFilteredPointsNonTrivialForMp.
/**
* We test the proper compilation of mp2sp with selector,
* treatment, vlan encapsulation and co-located
* filtered ingress/egress points.
*/
@Test
public void testCoLocatedDifferentFilteredPointsNonTrivialForMp() {
intent = LinkCollectionIntent.builder().appId(APP_ID).selector(ipPrefixSelector).treatment(ethDstTreatment).links(linksForMp2SpCoLoc).constraints(constraintsForVlan).filteredIngressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p10, mpls100Selector), new FilteredConnectPoint(d2p10, vlan100Selector))).filteredEgressPoints(ImmutableSet.of(new FilteredConnectPoint(d1p11, mpls200Selector))).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(ipPrefixSelector).matchInPort(d1p10.port()).matchMplsLabel(((MplsCriterion) mpls100Selector.getCriterion(MPLS_LABEL)).label()).build()));
assertThat(ruleS1.treatment(), is(DefaultTrafficTreatment.builder().setEthDst(((ModEtherInstruction) ethDstTreatment.allInstructions().stream().filter(instruction -> instruction instanceof ModEtherInstruction).findFirst().get()).mac()).setMpls(((MplsCriterion) mpls200Selector.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().setEthDst(((ModEtherInstruction) ethDstTreatment.allInstructions().stream().filter(instruction -> instruction instanceof ModEtherInstruction).findFirst().get()).mac()).popVlan().pushMpls().setMpls(((MplsCriterion) mpls200Selector.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(ipPrefixSelector).matchInPort(d2p10.port()).matchVlanId(((VlanIdCriterion) vlan100Selector.getCriterion(VLAN_VID)).vlanId()).build()));
assertThat(ruleS2.treatment(), is(DefaultTrafficTreatment.builder().setVlanId(VlanId.vlanId(LABEL)).setOutput(d2p0.port()).build()));
sut.deactivate();
}
use of org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction in project onos by opennetworkinglab.
the class FlowModBuilderVer13 method buildL2Modification.
protected OFAction buildL2Modification(Instruction i) {
L2ModificationInstruction l2m = (L2ModificationInstruction) i;
ModEtherInstruction eth;
OFOxm<?> oxm = null;
switch(l2m.subtype()) {
case ETH_DST:
eth = (ModEtherInstruction) l2m;
oxm = factory().oxms().ethDst(MacAddress.of(eth.mac().toLong()));
break;
case ETH_SRC:
eth = (ModEtherInstruction) l2m;
oxm = factory().oxms().ethSrc(MacAddress.of(eth.mac().toLong()));
break;
case VLAN_ID:
ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m;
oxm = factory().oxms().vlanVid(OFVlanVidMatch.ofVlan(vlanId.vlanId().toShort()));
break;
case VLAN_PCP:
ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m;
oxm = factory().oxms().vlanPcp(VlanPcp.of(vlanPcp.vlanPcp()));
break;
case MPLS_PUSH:
ModMplsHeaderInstruction pushHeaderInstructions = (ModMplsHeaderInstruction) l2m;
return factory().actions().pushMpls(EthType.of(pushHeaderInstructions.ethernetType().toShort()));
case MPLS_POP:
ModMplsHeaderInstruction popHeaderInstructions = (ModMplsHeaderInstruction) l2m;
return factory().actions().popMpls(EthType.of(popHeaderInstructions.ethernetType().toShort()));
case MPLS_LABEL:
ModMplsLabelInstruction mplsLabel = (ModMplsLabelInstruction) l2m;
oxm = factory().oxms().mplsLabel(U32.of(mplsLabel.label().toInt()));
break;
case MPLS_BOS:
ModMplsBosInstruction mplsBos = (ModMplsBosInstruction) l2m;
oxm = factory().oxms().mplsBos(mplsBos.mplsBos() ? OFBooleanValue.TRUE : OFBooleanValue.FALSE);
break;
case DEC_MPLS_TTL:
return factory().actions().decMplsTtl();
case VLAN_POP:
return factory().actions().popVlan();
case VLAN_PUSH:
ModVlanHeaderInstruction pushVlanInstruction = (ModVlanHeaderInstruction) l2m;
return factory().actions().pushVlan(EthType.of(pushVlanInstruction.ethernetType().toShort()));
case TUNNEL_ID:
ModTunnelIdInstruction tunnelId = (ModTunnelIdInstruction) l2m;
oxm = factory().oxms().tunnelId(U64.of(tunnelId.tunnelId()));
break;
default:
log.warn("Unimplemented action type {}.", l2m.subtype());
break;
}
if (oxm != null) {
return factory().actions().buildSetField().setField(oxm).build();
}
return null;
}
use of org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction in project onos by opennetworkinglab.
the class FlowModBuilderVer10 method buildL2Modification.
private OFAction buildL2Modification(Instruction i) {
L2ModificationInstruction l2m = (L2ModificationInstruction) i;
ModEtherInstruction eth;
switch(l2m.subtype()) {
case ETH_DST:
eth = (ModEtherInstruction) l2m;
return factory().actions().setDlDst(MacAddress.of(eth.mac().toLong()));
case ETH_SRC:
eth = (ModEtherInstruction) l2m;
return factory().actions().setDlSrc(MacAddress.of(eth.mac().toLong()));
case VLAN_ID:
ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m;
return factory().actions().setVlanVid(VlanVid.ofVlan(vlanId.vlanId().toShort()));
case VLAN_PCP:
ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m;
return factory().actions().setVlanPcp(VlanPcp.of(vlanPcp.vlanPcp()));
case VLAN_POP:
return factory().actions().stripVlan();
case VLAN_PUSH:
return null;
default:
log.warn("Unimplemented action type {}.", l2m.subtype());
break;
}
return null;
}
use of org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction in project onos by opennetworkinglab.
the class InstructionJsonMatcher method matchModEtherInstruction.
/**
* Matches the contents of a mod Ethernet instruction.
*
* @param instructionJson JSON instruction to match
* @param description Description object used for recording errors
* @return true if contents match, false otherwise
*/
private boolean matchModEtherInstruction(JsonNode instructionJson, Description description) {
ModEtherInstruction instructionToMatch = (ModEtherInstruction) instruction;
final String jsonSubtype = instructionJson.get("subtype").textValue();
if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
description.appendText("subtype was " + jsonSubtype);
return false;
}
final String jsonType = instructionJson.get("type").textValue();
if (!instructionToMatch.type().name().equals(jsonType)) {
description.appendText("type was " + jsonType);
return false;
}
final String jsonMac = instructionJson.get("mac").textValue();
final String mac = instructionToMatch.mac().toString();
if (!mac.equals(jsonMac)) {
description.appendText("mac was " + jsonMac);
return false;
}
return true;
}
use of org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction in project onos by opennetworkinglab.
the class InstructionJsonMatcher method matchesSafely.
@Override
public boolean matchesSafely(JsonNode jsonInstruction, Description description) {
// check type
final JsonNode jsonTypeNode = jsonInstruction.get("type");
final String jsonType = jsonTypeNode.textValue();
final String type = instruction.type().name();
if (!jsonType.equals(type)) {
description.appendText("type was " + type);
return false;
}
if (instruction instanceof ModMplsHeaderInstruction) {
return matchModMplsHeaderInstruction(jsonInstruction, description);
} else if (instruction instanceof OutputInstruction) {
return matchOutputInstruction(jsonInstruction, description);
} else if (instruction instanceof GroupInstruction) {
return matchGroupInstruction(jsonInstruction, description);
} else if (instruction instanceof MeterInstruction) {
return matchMeterInstruction(jsonInstruction, description);
} else if (instruction instanceof SetQueueInstruction) {
return matchSetQueueInstruction(jsonInstruction, description);
} else if (instruction instanceof ModOchSignalInstruction) {
return matchModOchSingalInstruction(jsonInstruction, description);
} else if (instruction instanceof ModEtherInstruction) {
return matchModEtherInstruction(jsonInstruction, description);
} else if (instruction instanceof ModVlanIdInstruction) {
return matchModVlanIdInstruction(jsonInstruction, description);
} else if (instruction instanceof ModVlanPcpInstruction) {
return matchModVlanPcpInstruction(jsonInstruction, description);
} else if (instruction instanceof ModIPInstruction) {
return matchModIpInstruction(jsonInstruction, description);
} else if (instruction instanceof ModIPv6FlowLabelInstruction) {
return matchModIPv6FlowLabelInstruction(jsonInstruction, description);
} else if (instruction instanceof ModMplsLabelInstruction) {
return matchModMplsLabelInstruction(jsonInstruction, description);
} else if (instruction instanceof ModOduSignalIdInstruction) {
return matchModOduSingalIdInstruction(jsonInstruction, description);
} else if (instruction instanceof PiInstruction) {
return matchPiInstruction(jsonInstruction, description);
} else if (instruction instanceof NoActionInstruction) {
return true;
}
return false;
}
Aggregations