use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.
the class FibInstaller method addNextHop.
private synchronized void addNextHop(ResolvedRoute route) {
prefixToNextHop.put(route.prefix(), route.nextHop());
if (nextHopsCount.count(route.nextHop()) == 0) {
// There was no next hop in the multiset
Interface egressIntf = interfaceService.getMatchingInterface(route.nextHop());
if (egressIntf == null) {
log.warn("no egress interface found for {}", route);
return;
}
NextHopGroupKey groupKey = new NextHopGroupKey(route.nextHop());
NextHop nextHop = new NextHop(route.nextHop(), route.nextHopMac(), groupKey);
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder().setEthSrc(egressIntf.mac()).setEthDst(nextHop.mac());
TrafficSelector.Builder metabuilder = null;
if (!egressIntf.vlan().equals(VlanId.NONE)) {
treatment.pushVlan().setVlanId(egressIntf.vlan()).setVlanPcp((byte) 0);
} else {
// untagged outgoing port may require internal vlan in some pipelines
metabuilder = DefaultTrafficSelector.builder();
metabuilder.matchVlanId(VlanId.vlanId(ASSIGNED_VLAN));
}
treatment.setOutput(egressIntf.connectPoint().port());
int nextId = flowObjectiveService.allocateNextId();
NextObjective.Builder nextBuilder = DefaultNextObjective.builder().withId(nextId).addTreatment(treatment.build()).withType(NextObjective.Type.SIMPLE).fromApp(fibAppId);
if (metabuilder != null) {
nextBuilder.withMeta(metabuilder.build());
}
// TODO add callbacks
NextObjective nextObjective = nextBuilder.add();
flowObjectiveService.next(deviceId, nextObjective);
nextHops.put(nextHop.ip(), nextId);
if (routeToNextHop) {
// Install route to next hop
ForwardingObjective fob = generateRibForwardingObj(IpPrefix.valueOf(route.nextHop(), 32), nextId).add();
flowObjectiveService.forward(deviceId, fob);
}
}
nextHopsCount.add(route.nextHop());
}
use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.
the class FibInstallerTest method testRouteAddWithVlan.
/**
* Tests adding a route with to a next hop in a VLAN.
*
* We verify that the flowObjectiveService records the correct state and that the
* correct flowObjectiveService is submitted to the flowObjectiveService.
*/
@Test
public void testRouteAddWithVlan() {
ResolvedRoute route = createRoute(PREFIX1, NEXT_HOP2, MAC2);
// Create the next objective
NextObjective nextObjective = createNextObjective(MAC2, MAC2, SW1_ETH2.port(), VLAN1, true);
flowObjectiveService.next(DEVICE_ID, nextObjective);
// Create the flow objective
ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
flowObjectiveService.forward(DEVICE_ID, fwd);
EasyMock.expectLastCall().once();
setUpFlowObjectiveService();
// Send in the add event
routeListener.event(new RouteEvent(RouteEvent.Type.ROUTE_ADDED, route));
verify(flowObjectiveService);
}
use of org.onosproject.net.flowobjective.NextObjective in project onos by opennetworkinglab.
the class FibInstallerTest method testRouteAdd.
/**
* Tests adding a route.
*
* We verify that the flowObjectiveService records the correct state and that the
* correct flow is submitted to the flowObjectiveService.
*/
@Test
public void testRouteAdd() {
ResolvedRoute resolvedRoute = createRoute(PREFIX1, NEXT_HOP1, MAC1);
// Create the next objective
NextObjective nextObjective = createNextObjective(MAC1, MAC1, SW1_ETH1.port(), VlanId.NONE, true);
flowObjectiveService.next(DEVICE_ID, nextObjective);
// Create the flow objective
ForwardingObjective fwd = createForwardingObjective(PREFIX1, true);
flowObjectiveService.forward(DEVICE_ID, fwd);
EasyMock.expectLastCall().once();
setUpFlowObjectiveService();
// Send in the add event
RouteEvent routeEvent = new RouteEvent(RouteEvent.Type.ROUTE_ADDED, resolvedRoute);
routeListener.event(routeEvent);
verify(flowObjectiveService);
}
use of org.onosproject.net.flowobjective.NextObjective in project trellis-control by opennetworkinglab.
the class DefaultGroupHandler method processEdgePort.
/**
* Adds or removes a port that has been configured with a vlan to a broadcast group
* for bridging. Should only be called by the instance leading the programming
* for this device.
*
* @param port the port on this device that needs to be added/removed to a bcast group
* @param vlanId the vlan id corresponding to the broadcast domain/group
* @param popVlan indicates if packets should be sent out untagged or not out
* of the port. If true, indicates an access (untagged) or native vlan
* configuration. If false, indicates a trunk (tagged) vlan config.
* @param portUp true if port is enabled, false if disabled
*/
public void processEdgePort(PortNumber port, VlanId vlanId, boolean popVlan, boolean portUp) {
// get the next id for the subnet and edit it.
Integer nextId = getVlanNextObjectiveId(vlanId);
if (nextId == -1) {
if (portUp) {
log.debug("**Creating flooding group for first port enabled in" + " vlan {} on dev {} port {}", vlanId, deviceId, port);
createBcastGroupFromVlan(vlanId, Collections.singleton(port));
} else {
log.warn("Could not find flooding group for subnet {} on dev:{} when" + " removing port:{}", vlanId, deviceId, port);
}
return;
}
log.info("**port{} in device {}: {} Bucket with Port {} to" + " next-id {}", (portUp) ? "UP" : "DOWN", deviceId, (portUp) ? "Adding" : "Removing", port, nextId);
// Create the bucket to be added or removed
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
if (popVlan) {
tBuilder.popVlan();
}
tBuilder.setOutput(port);
TrafficSelector metadata = DefaultTrafficSelector.builder().matchVlanId(vlanId).build();
NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.BROADCAST).fromApp(appId).addTreatment(tBuilder.build()).withMeta(metadata);
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("port {} successfully {} NextObj {} on {}", port, (portUp) ? "addedTo" : "removedFrom", nextId, deviceId), (objective, error) -> {
log.warn("port {} failed to {} NextObj {} on {}: {}", port, (portUp) ? "addTo" : "removeFrom", nextId, deviceId, error);
srManager.invalidateNextObj(objective.id());
});
NextObjective nextObj = (portUp) ? nextObjBuilder.addToExisting(context) : nextObjBuilder.removeFromExisting(context);
log.debug("edgePort processed: Submited next objective {} in device {}", nextId, deviceId);
flowObjectiveService.next(deviceId, nextObj);
}
use of org.onosproject.net.flowobjective.NextObjective in project trellis-control by opennetworkinglab.
the class DefaultGroupHandler method removeGroupFromPort.
/**
* Remove simple next objective for a single port. The treatments can include
* all outgoing actions that need to happen on the packet.
*
* @param portNum the outgoing port on the device
* @param treatment the actions applied on the packets (should include outport)
* @param meta optional data to pass to the driver
* @return a completable future that completes when the port has been removed
*/
public CompletableFuture<Objective> removeGroupFromPort(PortNumber portNum, TrafficTreatment treatment, TrafficSelector meta) {
PortNextObjectiveStoreKey key = new PortNextObjectiveStoreKey(deviceId, portNum, treatment, meta);
Integer nextId = portNextObjStore.get(key);
CompletableFuture<Objective> future = new CompletableFuture<>();
NextObjective.Builder nextObjBuilder = DefaultNextObjective.builder().withId(nextId).withType(NextObjective.Type.SIMPLE).addTreatment(treatment).fromApp(appId).withMeta(meta);
ObjectiveContext context = new DefaultObjectiveContext((objective) -> {
log.info("removeGroupFromPort done " + "NextObj {} on {}", nextId, deviceId);
future.complete(objective);
}, (objective, error) -> {
log.warn("removeGroupFromPort failed to install NextObj {} on {}: {}", nextId, deviceId, error);
srManager.invalidateNextObj(objective.id());
future.complete(null);
});
NextObjective nextObj = nextObjBuilder.remove(context);
flowObjectiveService.next(deviceId, nextObj);
log.info("removeGroupFromPort: Submitted next objective {} in device {} " + "for port {}", nextId, deviceId, portNum);
portNextObjStore.remove(key);
return future;
}
Aggregations