use of org.onosproject.net.EncapsulationType in project onos by opennetworkinglab.
the class PathIntentCompilerTest method testVlanEncapCompileSingleHopDirectVlan.
/**
* 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. Ingress VLAN. Egress VLAN.
*/
@Test
public void testVlanEncapCompileSingleHopDirectVlan() {
sut.activate();
List<Intent> compiled = sut.compile(singleHopDirectIntentVlan, 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()).matchVlanId(ingressVlan).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.EncapsulationType in project onos by opennetworkinglab.
the class SdnIpFib method setEncap.
/**
* Sets an encapsulation constraint to the intent builder given.
*
* @param builder the intent builder
* @param constraints the existing intent constraints
* @param encap the encapsulation type to be set
*/
private static void setEncap(ConnectivityIntent.Builder builder, List<Constraint> constraints, EncapsulationType encap) {
// Constraints might be an immutable list, so a new modifiable list
// is created
List<Constraint> newConstraints = new ArrayList<>(constraints);
// Remove any encapsulation constraint if already in the list
constraints.stream().filter(c -> c instanceof EncapsulationConstraint).forEach(c -> newConstraints.remove(c));
// constraint should be added to the list
if (!encap.equals(NONE)) {
newConstraints.add(new EncapsulationConstraint(encap));
}
// Submit new constraint list as immutable list
builder.constraints(ImmutableList.copyOf(newConstraints));
}
use of org.onosproject.net.EncapsulationType in project onos by opennetworkinglab.
the class SdnIpConfig method encap.
/**
* Retrieves the encapsulation type set.
*
* @return the encapsulation type configured
*/
public EncapsulationType encap() {
EncapsulationType encapType = EncapsulationType.NONE;
if (object.hasNonNull(ENCAPSULTATION)) {
String encap = object.get(ENCAPSULTATION).asText();
encapType = EncapsulationType.enumFromString(encap);
}
return encapType;
}
use of org.onosproject.net.EncapsulationType in project onos by opennetworkinglab.
the class SimpleFabricRouting method ipPacketReactiveProcessor.
/**
* Routes packet reactively.
*/
private void ipPacketReactiveProcessor(PacketContext context, Ethernet ethPkt, ConnectPoint srcCp, IpAddress srcIp, IpAddress dstIp, byte ipProto) {
/* check reactive handling and forward packet */
log.trace("ip packet: srcCp={} srcIp={} dstIp={} ipProto={}", srcCp, srcIp, dstIp, ipProto);
EncapsulationType encap = EncapsulationType.NONE;
// prefix and nextHop for local Subnet
IpPrefix srcPrefix = srcIp.toIpPrefix();
IpPrefix dstPrefix = dstIp.toIpPrefix();
IpAddress srcNextHop = srcIp;
IpAddress dstNextHop = dstIp;
MacAddress treatmentSrcMac = ethPkt.getDestinationMAC();
int borderRoutePrefixLength = 0;
boolean updateMac = simpleFabric.isVirtualGatewayMac(ethPkt.getDestinationMAC());
// check subnet local or route
FabricSubnet srcSubnet = simpleFabric.fabricSubnet(srcIp);
if (srcSubnet == null) {
FabricRoute route = simpleFabric.fabricRoute(srcIp);
if (route == null) {
log.warn("unknown srcIp; drop: srcCp={} srcIp={} dstIp={} ipProto={}", srcCp, srcIp, dstIp, ipProto);
return;
}
srcPrefix = route.prefix();
srcNextHop = route.nextHop();
borderRoutePrefixLength = route.prefix().prefixLength();
}
FabricSubnet dstSubnet = simpleFabric.fabricSubnet(dstIp);
if (dstSubnet == null) {
FabricRoute route = simpleFabric.fabricRoute(dstIp);
if (route == null) {
log.warn("unknown dstIp; drop: srcCp={} srcIp={} dstIp={} ipProto={}", srcCp, srcIp, dstIp, ipProto);
return;
}
dstPrefix = route.prefix();
dstNextHop = route.nextHop();
borderRoutePrefixLength = route.prefix().prefixLength();
}
if (dstSubnet != null) {
// destination is local subnet ip
if (ALLOW_ETH_ADDRESS_SELECTOR && dstSubnet.equals(srcSubnet)) {
// NOTE: if ALLOW_ETH_ADDRESS_SELECTOR=false; isForward is always false
FabricNetwork fabricNetwork = simpleFabric.fabricNetwork(dstSubnet.networkName());
treatmentSrcMac = ethPkt.getSourceMAC();
if (fabricNetwork != null && fabricNetwork.isForward()) {
// NOTE: no reactive route action but do forward packet for L2Forward do not handle packet
// update mac only if dstMac is virtualGatewayMac, else assume valid mac already for the l2 network
log.info("LOCAL FORWARD ONLY: " + "srcCp={} srcIp={} dstIp={} srcMac={} dstMac={} vlanId={} ipProto={} updateMac={}", context.inPacket().receivedFrom(), srcIp, dstIp, ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(), ethPkt.getVlanID(), ipProto, updateMac);
forwardPacketToDstIp(context, dstIp, treatmentSrcMac, updateMac);
return;
}
}
encap = dstSubnet.encapsulation();
if (encap == EncapsulationType.NONE && srcSubnet != null) {
encap = srcSubnet.encapsulation();
}
} else {
// destination is external network
if (srcSubnet == null) {
// both are externel network
log.warn("INVALID PACKET: srcIp and dstIp are both NON-LOCAL: " + "srcCP={} srcIp={} dstIp={} srcMac={} dstMac={} vlanId={} ipProto={} updateMac={}", context.inPacket().receivedFrom(), srcIp, dstIp, ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(), ethPkt.getVlanID(), ipProto, updateMac);
return;
}
encap = srcSubnet.encapsulation();
}
log.info("REGI AND FORWARD: " + "srcCP={} srcIp={} dstIp={} srcMac={} dstMac={} vlanId={} ipProto={} updateMac={}", context.inPacket().receivedFrom(), srcIp, dstIp, ethPkt.getSourceMAC(), ethPkt.getDestinationMAC(), ethPkt.getVlanID(), ipProto, updateMac);
setUpConnectivity(srcCp, ipProto, srcPrefix, dstPrefix, dstNextHop, treatmentSrcMac, encap, updateMac, dstSubnet != null, borderRoutePrefixLength);
forwardPacketToDstIp(context, dstNextHop, treatmentSrcMac, updateMac);
}
use of org.onosproject.net.EncapsulationType in project onos by opennetworkinglab.
the class VplsIntentTest method generateVplsBrc.
/**
* Generates a list of the expected sp2mp intents for a VPLS.
*
* @param fcPoints the filtered connect point
* @param name the name of the VPLS
* @param encap the encapsulation type
* @return the list of expected sp2mp intents for the given VPLS
*/
private List<SinglePointToMultiPointIntent> generateVplsBrc(Set<FilteredConnectPoint> fcPoints, String name, EncapsulationType encap) {
List<SinglePointToMultiPointIntent> intents = Lists.newArrayList();
fcPoints.forEach(point -> {
Set<FilteredConnectPoint> otherPoints = fcPoints.stream().filter(fcp -> !fcp.equals(point)).collect(Collectors.toSet());
Key brckey = buildKey(VplsIntentUtility.PREFIX_BROADCAST, point.connectPoint(), name, MacAddress.BROADCAST);
intents.add(buildBrcIntent(brckey, point, otherPoints, encap));
});
return intents;
}
Aggregations