use of org.onosproject.net.flowobjective.Objective in project onos by opennetworkinglab.
the class DhcpRelayManagerTest method testInstallIgnoreRuleWhenDeviceComesUp.
/**
* Should try install ignore rules when device comes up.
*/
@Test
public void testInstallIgnoreRuleWhenDeviceComesUp() throws IOException {
ObjectMapper om = new ObjectMapper();
JsonNode json = om.readTree(Resources.getResource(CONFIG_FILE_PATH));
IgnoreDhcpConfig config = new IgnoreDhcpConfig();
json = json.path("apps").path(DHCP_RELAY_APP).path(IgnoreDhcpConfig.KEY);
config.init(APP_ID, IgnoreDhcpConfig.KEY, json, om, null);
reset(manager.cfgService, flowObjectiveService, manager.deviceService);
expect(manager.cfgService.getConfig(APP_ID, IgnoreDhcpConfig.class)).andReturn(config).anyTimes();
Device device = createNiceMock(Device.class);
expect(device.is(Pipeliner.class)).andReturn(true).anyTimes();
expect(device.id()).andReturn(DEV_1_ID).anyTimes();
expect(manager.deviceService.getDevice(DEV_1_ID)).andReturn(device).anyTimes();
DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device);
Capture<Objective> capturedFromDev1 = newCapture(CaptureType.ALL);
flowObjectiveService.apply(eq(DEV_1_ID), capture(capturedFromDev1));
expectLastCall().times(DHCP_SELECTORS.size());
replay(manager.cfgService, flowObjectiveService, manager.deviceService, device);
manager.deviceListener.event(event);
// Wait until all flow objective events are captured before triggering onSuccess
int expectFlowObjCount = Dhcp4HandlerImpl.DHCP_SELECTORS.size() + Dhcp6HandlerImpl.DHCP_SELECTORS.size();
assertAfter(EVENT_PROCESSING_MS, () -> assertEquals(expectFlowObjCount, capturedFromDev1.getValues().size()));
capturedFromDev1.getValues().forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj)));
assertAfter(EVENT_PROCESSING_MS, () -> assertEquals(1, v4Handler.ignoredVlans.size()));
assertAfter(EVENT_PROCESSING_MS, () -> assertEquals(1, v6Handler.ignoredVlans.size()));
}
use of org.onosproject.net.flowobjective.Objective in project onos by opennetworkinglab.
the class DhcpRelayManagerTest method testIgnoreVlan.
/**
* Ignores specific vlans from specific devices if config.
*
* @throws Exception the exception from this test
*/
@Test
public void testIgnoreVlan() throws Exception {
ObjectMapper om = new ObjectMapper();
JsonNode json = om.readTree(Resources.getResource(CONFIG_FILE_PATH));
IgnoreDhcpConfig config = new IgnoreDhcpConfig();
json = json.path("apps").path(DHCP_RELAY_APP).path(IgnoreDhcpConfig.KEY);
config.init(APP_ID, IgnoreDhcpConfig.KEY, json, om, null);
Capture<Objective> capturedFromDev1 = newCapture(CaptureType.ALL);
flowObjectiveService.apply(eq(DEV_1_ID), capture(capturedFromDev1));
expectLastCall().times(DHCP_SELECTORS.size());
Capture<Objective> capturedFromDev2 = newCapture(CaptureType.ALL);
flowObjectiveService.apply(eq(DEV_2_ID), capture(capturedFromDev2));
expectLastCall().times(DHCP_SELECTORS.size());
replay(flowObjectiveService);
manager.updateConfig(config);
verify(flowObjectiveService);
List<Objective> objectivesFromDev1 = capturedFromDev1.getValues();
List<Objective> objectivesFromDev2 = capturedFromDev2.getValues();
assertTrue(objectivesFromDev1.containsAll(objectivesFromDev2));
assertTrue(objectivesFromDev2.containsAll(objectivesFromDev1));
for (int index = 0; index < objectivesFromDev1.size(); index++) {
TrafficSelector selector = DefaultTrafficSelector.builder(DHCP_SELECTORS.get(index)).matchVlanId(IGNORED_VLAN).build();
ForwardingObjective fwd = (ForwardingObjective) objectivesFromDev1.get(index);
assertEquals(selector, fwd.selector());
assertEquals(DefaultTrafficTreatment.emptyTreatment(), fwd.treatment());
assertEquals(IGNORE_CONTROL_PRIORITY, fwd.priority());
assertEquals(ForwardingObjective.Flag.VERSATILE, fwd.flag());
assertEquals(Objective.Operation.ADD, fwd.op());
fwd.context().ifPresent(ctx -> {
ctx.onSuccess(fwd);
});
}
objectivesFromDev2.forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj)));
assertEquals(2, v4Handler.ignoredVlans.size());
assertEquals(2, v6Handler.ignoredVlans.size());
}
use of org.onosproject.net.flowobjective.Objective in project trellis-control by opennetworkinglab.
the class HostHandler method processIntfVlanUpdatedEvent.
/**
* Update forwarding objective for unicast bridging and unicast routing.
* Also check the validity of updated interface configuration on VLAN.
*
* @param deviceId device ID that host attaches to
* @param portNum port number that host attaches to
* @param vlanId Vlan ID configured on the switch port
* @param popVlan true to pop Vlan tag at TrafficTreatment, false otherwise
* @param install true to populate the objective, false to revoke
*/
// TODO Current implementation does not handle dual-homed hosts with auxiliary locations.
void processIntfVlanUpdatedEvent(DeviceId deviceId, PortNumber portNum, VlanId vlanId, boolean popVlan, boolean install) {
ConnectPoint connectPoint = new ConnectPoint(deviceId, portNum);
Set<Host> hosts = hostService.getConnectedHosts(connectPoint);
if (hosts == null || hosts.size() == 0) {
log.debug("processIntfVlanUpdatedEvent: No hosts connected to {}", connectPoint);
return;
}
List<CompletableFuture<Void>> hostFutures = Lists.newArrayList();
hosts.forEach(host -> hostFutures.add(hostWorkers.submit(() -> processIntfVlanUpdatedEventInternal(host, deviceId, portNum, vlanId, popVlan, install), host.id().hashCode())));
// Let's wait for the completion of all hosts
try {
CompletableFuture.allOf(hostFutures.toArray(new CompletableFuture[0])).thenApply(objectives -> hostFutures.stream().map(CompletableFuture::join).collect(Collectors.toList())).get();
} catch (InterruptedException | ExecutionException e) {
log.warn("Exception caught when executing processIntfVlanUpdatedEvent futures");
hostFutures.forEach(future -> future.cancel(false));
}
}
use of org.onosproject.net.flowobjective.Objective 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.Objective 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