use of org.onosproject.net.flowobjective.ObjectiveContext in project onos by opennetworkinglab.
the class InOrderFlowObjectiveManagerTest method forwardTimeout.
@Test
public void forwardTimeout() {
final AtomicInteger counter = new AtomicInteger(0);
ForwardingObjective fwdTimeout = buildFwdObjective(S1, NID2).add(new ObjectiveContext() {
@Override
public void onError(Objective objective, ObjectiveError error) {
if (Objects.equals(ObjectiveError.INSTALLATIONTIMEOUT, error)) {
counter.incrementAndGet();
}
}
});
List<ForwardingObjective> expectFwdObjsTimeout = Lists.newCopyOnWriteArrayList(Lists.newArrayList(fwdTimeout, FWD1, FWD2));
// Reduce timeout so the unit test doesn't have to wait many seconds
internalSetup(TIMEOUT_THRESH);
expect(mgr.flowObjectiveStore.getNextGroup(NID1)).andReturn(NGRP1).times(1);
expect(mgr.flowObjectiveStore.getNextGroup(NID2)).andReturn(NGRP2).times(2);
replay(mgr.flowObjectiveStore);
// Force this objective to time out
offset = mgr.objectiveTimeoutMs * 3;
expectFwdObjsTimeout.forEach(fwdObj -> mgr.forward(DEV1, fwdObj));
// Wait for the pipeline operation to complete
int expectedTime = (bound + offset) * 3;
assertAfter(expectedTime, expectedTime * 5, () -> assertEquals(expectFwdObjsTimeout.size(), actualObjs.size()));
assertAfter(expectedTime, expectedTime * 5, () -> assertTrue(counter.get() != 0));
assertTrue(actualObjs.indexOf(fwdTimeout) < actualObjs.indexOf(FWD1));
verify(mgr.flowObjectiveStore);
}
use of org.onosproject.net.flowobjective.ObjectiveContext in project trellis-control by opennetworkinglab.
the class AppConfigHandler method populateVRouter.
private void populateVRouter(DeviceId deviceId, Set<MacAddress> pendingAdd) {
if (!isEdge(deviceId)) {
return;
}
getVRouterFlowObjBuilders(pendingAdd).forEach(foBuilder -> {
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("vRouterMac filter for {} populated", pendingAdd), (objective, error) -> log.warn("Failed to populate vRouterMac filter for {}: {}", pendingAdd, error));
srManager.flowObjectiveService.filter(deviceId, foBuilder.add(context));
});
}
use of org.onosproject.net.flowobjective.ObjectiveContext in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method updateDefaultRouteBlackhole.
private void updateDefaultRouteBlackhole(DeviceId deviceId, IpPrefix address, boolean install) {
try {
if (srManager.deviceConfiguration.isEdgeDevice(deviceId)) {
TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder();
if (address.isIp4()) {
sbuilder.matchIPDst(address);
sbuilder.matchEthType(EthType.EtherType.IPV4.ethType().toShort());
} else {
sbuilder.matchIPv6Dst(address);
sbuilder.matchEthType(EthType.EtherType.IPV6.ethType().toShort());
}
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
tBuilder.wipeDeferred();
ForwardingObjective.Builder fob = DefaultForwardingObjective.builder();
fob.withFlag(Flag.SPECIFIC).withSelector(sbuilder.build()).withTreatment(tBuilder.build()).withPriority(getPriorityFromPrefix(address)).fromApp(srManager.appId).makePermanent();
log.debug("{} blackhole forwarding objectives for dev: {}", install ? "Installing" : "Removing", deviceId);
ObjectiveContext context = new DefaultObjectiveContext((objective) -> log.debug("Forward for {} {}", deviceId, install ? "installed" : "removed"), (objective, error) -> log.warn("Failed to {} forward for {}: {}", install ? "install" : "remove", deviceId, error));
if (install) {
srManager.flowObjectiveService.forward(deviceId, fob.add(context));
} else {
srManager.flowObjectiveService.forward(deviceId, fob.remove(context));
}
}
} catch (DeviceConfigNotFoundException e) {
log.info("Not populating blackhole for un-configured device {}", deviceId);
}
}
use of org.onosproject.net.flowobjective.ObjectiveContext in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method revokeRoute.
/**
* Removes IP rules for a route when the next hop is gone.
* This method should not be invoked directly without going through DefaultRoutingHandler.
*
* @param deviceId device ID of the device that next hop attaches to
* @param prefix IP prefix of the route
* @param hostMac MAC address of the next hop
* @param hostVlanId Vlan ID of the nexthop
* @param outPort port that next hop attaches to
* @param directHost host is of type direct or indirect
* @return future that carries the flow objective if succeeded, null if otherwise
*/
CompletableFuture<Objective> revokeRoute(DeviceId deviceId, IpPrefix prefix, MacAddress hostMac, VlanId hostVlanId, PortNumber outPort, boolean directHost) {
log.debug("Revoke IP table entry for route {} at {}:{}", prefix, deviceId, outPort);
ForwardingObjective.Builder fwdBuilder;
try {
fwdBuilder = routingFwdObjBuilder(deviceId, prefix, hostMac, hostVlanId, outPort, null, null, directHost, true);
} catch (DeviceConfigNotFoundException e) {
log.warn(e.getMessage() + " Aborting revokeIpRuleForHost.");
return CompletableFuture.completedFuture(null);
}
if (fwdBuilder == null) {
log.warn("Aborting host routing table entries due " + "to error for dev:{} route:{}", deviceId, prefix);
return CompletableFuture.completedFuture(null);
}
CompletableFuture<Objective> future = new CompletableFuture<>();
ObjectiveContext context = new DefaultObjectiveContext((objective) -> {
log.debug("IP rule for route {} revoked", prefix);
future.complete(objective);
}, (objective, error) -> {
log.warn("Failed to revoke IP rule for route {}: {}", prefix, error);
future.complete(null);
});
srManager.flowObjectiveService.forward(deviceId, fwdBuilder.remove(context));
return future;
}
use of org.onosproject.net.flowobjective.ObjectiveContext in project trellis-control by opennetworkinglab.
the class RoutingRulePopulator method populateBridging.
/**
* Populate a bridging rule on given deviceId that matches given mac, given vlan and
* output to given port.
*
* @param deviceId device ID
* @param port port
* @param mac mac address
* @param vlanId VLAN ID
* @return future that carries the flow objective if succeeded, null if otherwise
*/
CompletableFuture<Objective> populateBridging(DeviceId deviceId, PortNumber port, MacAddress mac, VlanId vlanId) {
ForwardingObjective.Builder fob = bridgingFwdObjBuilder(deviceId, mac, vlanId, port, false);
if (fob == null) {
log.warn("Fail to build fwd obj for host {}/{}. Abort.", mac, vlanId);
return CompletableFuture.completedFuture(null);
}
CompletableFuture<Objective> future = new CompletableFuture<>();
ObjectiveContext context = new DefaultObjectiveContext((objective) -> {
log.debug("Brigding rule for {}/{} populated", mac, vlanId);
future.complete(objective);
}, (objective, error) -> {
log.warn("Failed to populate bridging rule for {}/{}: {}", mac, vlanId, error);
future.complete(null);
});
srManager.flowObjectiveService.forward(deviceId, fob.add(context));
return future;
}
Aggregations