use of org.onosproject.net.flowobjective.ForwardingObjective in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method populateArpNdpPunts.
/**
* Creates forwarding objectives to punt ARP and NDP packets, to the controller.
* Furthermore, these are applied only by the master instance. Deferred actions
* are not cleared such that packets can be flooded in the cross connect use case
*
* @param deviceId the switch dpid for the router
*/
void populateArpNdpPunts(DeviceId deviceId) {
// We are not the master just skip.
if (!srManager.shouldProgram(deviceId)) {
log.debug("Not installing ARP/NDP punts - not handling programming for dev:{} ", deviceId);
return;
}
ForwardingObjective fwdObj;
// We punt all ARP packets towards the controller.
fwdObj = arpFwdObjective(null, true, ARP_NDP_PRIORITY).add(new ObjectiveContext() {
@Override
public void onError(Objective objective, ObjectiveError error) {
log.warn("Failed to install forwarding objective to punt ARP to {}: {}", deviceId, error);
}
});
srManager.flowObjectiveService.forward(deviceId, fwdObj);
if (isIpv6Configured(deviceId)) {
// We punt all NDP packets towards the controller.
ndpFwdObjective(null, true, ARP_NDP_PRIORITY).forEach(builder -> {
ForwardingObjective obj = builder.add(new ObjectiveContext() {
@Override
public void onError(Objective objective, ObjectiveError error) {
log.warn("Failed to install forwarding objective to punt NDP to {}: {}", deviceId, error);
}
});
srManager.flowObjectiveService.forward(deviceId, obj);
});
}
srManager.getPairLocalPort(deviceId).ifPresent(port -> {
ForwardingObjective pairFwdObj;
// Do not punt ARP packets from pair port
pairFwdObj = arpFwdObjective(port, false, PacketPriority.CONTROL.priorityValue() + 1).add(new ObjectiveContext() {
@Override
public void onError(Objective objective, ObjectiveError error) {
log.warn("Failed to install forwarding objective to ignore ARP to {}: {}", deviceId, error);
}
});
srManager.flowObjectiveService.forward(deviceId, pairFwdObj);
if (isIpv6Configured(deviceId)) {
// Do not punt NDP packets from pair port
ndpFwdObjective(port, false, PacketPriority.CONTROL.priorityValue() + 1).forEach(builder -> {
ForwardingObjective obj = builder.add(new ObjectiveContext() {
@Override
public void onError(Objective objective, ObjectiveError error) {
log.warn("Failed to install forwarding objective to ignore ARP to {}: {}", deviceId, error);
}
});
srManager.flowObjectiveService.forward(deviceId, obj);
});
// Do not forward DAD packets from pair port
pairFwdObj = dad6FwdObjective(port, PacketPriority.CONTROL.priorityValue() + 2).add(new ObjectiveContext() {
@Override
public void onError(Objective objective, ObjectiveError error) {
log.warn("Failed to install forwarding objective to drop DAD to {}: {}", deviceId, error);
}
});
srManager.flowObjectiveService.forward(deviceId, pairFwdObj);
}
});
}
use of org.onosproject.net.flowobjective.ForwardingObjective in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method handleMpls.
/**
* Differentiates between popping and swapping labels when building an MPLS
* forwarding objective.
*
* @param targetSwId the target sw
* @param destSwId the destination sw
* @param nextHops the set of next hops
* @param segmentId the segmentId to match representing the destination
* switch
* @param routerIp the router ip representing the destination switch
* @return a collection of fwdobjective
*/
private Collection<ForwardingObjective> handleMpls(DeviceId targetSwId, DeviceId destSwId, Set<DeviceId> nextHops, int segmentId, IpAddress routerIp, boolean isMplsBos) {
TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
List<ForwardingObjective.Builder> fwdObjBuilders = Lists.newArrayList();
// For the transport of Pwaas we can use two or three MPLS label
sbuilder.matchEthType(Ethernet.MPLS_UNICAST);
sbuilder.matchMplsLabel(MplsLabel.mplsLabel(segmentId));
sbuilder.matchMplsBos(isMplsBos);
TrafficSelector selector = sbuilder.build();
// setup metadata to pass to nextObjective - indicate the vlan on egress
// if needed by the switch pipeline. Since mpls next-hops are always to
// other neighboring routers, there is no subnet assigned on those ports.
TrafficSelector.Builder metabuilder = DefaultTrafficSelector.builder(selector);
metabuilder.matchVlanId(srManager.getDefaultInternalVlan());
if (nextHops.size() == 1 && destSwId.equals(nextHops.toArray()[0])) {
// If the next hop is the destination router for the segment, do pop
log.debug("populateMplsRule: Installing MPLS forwarding objective for " + "label {} in switch {} with pop to next-hops {}", segmentId, targetSwId, nextHops);
ForwardingObjective.Builder fwdObjNoBosBuilder = getMplsForwardingObjective(targetSwId, nextHops, true, isMplsBos, metabuilder.build(), routerIp, segmentId, destSwId);
// Error case, we cannot handle, exit.
if (fwdObjNoBosBuilder == null) {
return Collections.emptyList();
}
fwdObjBuilders.add(fwdObjNoBosBuilder);
} else {
// next hop is not destination, irrespective of the number of next
// hops (1 or more) -- SR CONTINUE case (swap with self)
log.debug("Installing MPLS forwarding objective for " + "label {} in switch {} without pop to next-hops {}", segmentId, targetSwId, nextHops);
ForwardingObjective.Builder fwdObjNoBosBuilder = getMplsForwardingObjective(targetSwId, nextHops, false, isMplsBos, metabuilder.build(), routerIp, segmentId, destSwId);
// Error case, we cannot handle, exit.
if (fwdObjNoBosBuilder == null) {
return Collections.emptyList();
}
fwdObjBuilders.add(fwdObjNoBosBuilder);
}
List<ForwardingObjective> fwdObjs = Lists.newArrayList();
// We add the final property to the fwdObjs.
for (ForwardingObjective.Builder fwdObjBuilder : fwdObjBuilders) {
((Builder) ((Builder) fwdObjBuilder.fromApp(srManager.appId).makePermanent()).withSelector(selector).withPriority(SegmentRoutingService.DEFAULT_PRIORITY)).withFlag(ForwardingObjective.Flag.SPECIFIC);
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("MPLS rule {} for SID {} populated in dev:{} ", objective.id(), segmentId, targetSwId), (objective, error) -> log.warn("Failed to populate MPLS rule {} for SID {}: {} in dev:{}", objective.id(), segmentId, error, targetSwId));
ForwardingObjective fob = fwdObjBuilder.add(context);
fwdObjs.add(fob);
}
return fwdObjs;
}
use of org.onosproject.net.flowobjective.ForwardingObjective in project trellis-control by opennetworkinglab.
the class SRObjectiveMetadata method isValidSrMetadata.
/**
* Check metadata passed from SegmentRouting app.
*
* @param obj the objective containing the metadata
* @return true if the objective contains valid metadata, false otherwise
*/
public static boolean isValidSrMetadata(Objective obj) {
long meta = 0;
if (obj instanceof FilteringObjective) {
FilteringObjective filtObj = (FilteringObjective) obj;
if (filtObj.meta() == null) {
return true;
}
Instructions.MetadataInstruction metaIns = filtObj.meta().writeMetadata();
if (metaIns == null) {
return true;
}
meta = metaIns.metadata() & metaIns.metadataMask();
} else if (obj instanceof ForwardingObjective) {
ForwardingObjective fwdObj = (ForwardingObjective) obj;
if (fwdObj.meta() == null) {
return true;
}
MetadataCriterion metaCrit = (MetadataCriterion) fwdObj.meta().getCriterion(Criterion.Type.METADATA);
if (metaCrit == null) {
return true;
}
meta = metaCrit.metadata();
}
return meta != 0 && (meta ^ METADATA_MASK) <= METADATA_MASK;
}
use of org.onosproject.net.flowobjective.ForwardingObjective in project fabric-tna by stratum.
the class ForwardingFunctionTypeTest method testFft.
private void testFft(TrafficSelector selector, ForwardingFunctionType expectedFft) {
ForwardingObjective fwd = DefaultForwardingObjective.builder().withSelector(selector).withFlag(ForwardingObjective.Flag.SPECIFIC).nextStep(0).fromApp(APP_ID).add();
assertEquals(expectedFft, ForwardingFunctionType.getForwardingFunctionType(fwd));
}
use of org.onosproject.net.flowobjective.ForwardingObjective in project fabric-tna by stratum.
the class ForwardingObjectiveTranslatorTest method testAclArp.
/**
* Test versatile flag of forwarding objective with ARP match.
*/
@Test
public void testAclArp() {
TrafficTreatment treatment = DefaultTrafficTreatment.builder().punt().build();
// ARP
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthType(Ethernet.TYPE_ARP).build();
ForwardingObjective fwd = DefaultForwardingObjective.builder().withSelector(selector).withPriority(PRIORITY).fromApp(APP_ID).makePermanent().withFlag(ForwardingObjective.Flag.VERSATILE).withTreatment(treatment).add();
ObjectiveTranslation result = translator.translate(fwd);
List<FlowRule> flowRulesInstalled = (List<FlowRule>) result.flowRules();
List<GroupDescription> groupsInstalled = (List<GroupDescription>) result.groups();
assertEquals(1, flowRulesInstalled.size());
assertEquals(0, groupsInstalled.size());
FlowRule actualFlowRule = flowRulesInstalled.get(0);
PiAction piAction = PiAction.builder().withId(P4InfoConstants.FABRIC_INGRESS_ACL_COPY_TO_CPU).build();
FlowRule expectedFlowRule = DefaultFlowRule.builder().forDevice(DEVICE_ID).forTable(P4InfoConstants.FABRIC_INGRESS_ACL_ACL).withPriority(PRIORITY).makePermanent().withSelector(selector).withTreatment(DefaultTrafficTreatment.builder().piTableAction(piAction).build()).fromApp(APP_ID).build();
assertTrue(expectedFlowRule.exactMatch(actualFlowRule));
}
Aggregations