use of org.onosproject.net.flowobjective.FlowObjectiveService in project onos by opennetworkinglab.
the class DhcpRelayManagerTest method testRemoveIgnoreVlan.
/**
* "IgnoreVlan" policy should be removed when the config removed.
*/
@Test
public void testRemoveIgnoreVlan() {
v4Handler.ignoredVlans.put(DEV_1_ID, IGNORED_VLAN);
v4Handler.ignoredVlans.put(DEV_2_ID, IGNORED_VLAN);
v6Handler.ignoredVlans.put(DEV_1_ID, IGNORED_VLAN);
v6Handler.ignoredVlans.put(DEV_2_ID, IGNORED_VLAN);
IgnoreDhcpConfig config = new IgnoreDhcpConfig();
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.removeConfig(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.REMOVE, fwd.op());
fwd.context().ifPresent(ctx -> {
ctx.onSuccess(fwd);
});
}
objectivesFromDev2.forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj)));
assertEquals(0, v4Handler.ignoredVlans.size());
assertEquals(0, v6Handler.ignoredVlans.size());
}
use of org.onosproject.net.flowobjective.FlowObjectiveService in project onos by opennetworkinglab.
the class DhcpRelayManagerTest method testIgnoreUnknownDevice.
/**
* Should ignore ignore rules installation when device not available.
*/
@Test
public void testIgnoreUnknownDevice() throws IOException {
reset(manager.deviceService);
Device device = createNiceMock(Device.class);
expect(device.is(Pipeliner.class)).andReturn(true).anyTimes();
expect(manager.deviceService.getDevice(DEV_1_ID)).andReturn(device).anyTimes();
expect(manager.deviceService.getDevice(DEV_2_ID)).andReturn(null).anyTimes();
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());
replay(flowObjectiveService, manager.deviceService, device);
manager.updateConfig(config);
capturedFromDev1.getValues().forEach(obj -> obj.context().ifPresent(ctx -> ctx.onSuccess(obj)));
assertEquals(1, v4Handler.ignoredVlans.size());
assertEquals(1, v6Handler.ignoredVlans.size());
}
use of org.onosproject.net.flowobjective.FlowObjectiveService 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.FlowObjectiveService 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.FlowObjectiveService in project onos by opennetworkinglab.
the class DhcpRelayManagerTest method setup.
@Before
public void setup() {
manager = new DhcpRelayManager();
manager.cfgService = createNiceMock(NetworkConfigRegistry.class);
expect(manager.cfgService.getConfig(APP_ID, DefaultDhcpRelayConfig.class)).andReturn(CONFIG).anyTimes();
expect(manager.cfgService.getConfig(APP_ID, IndirectDhcpRelayConfig.class)).andReturn(CONFIG_INDIRECT).anyTimes();
manager.coreService = createNiceMock(CoreService.class);
expect(manager.coreService.registerApplication(anyString())).andReturn(APP_ID).anyTimes();
manager.hostService = createNiceMock(HostService.class);
expect(manager.hostService.getHostsByIp(OUTER_RELAY_IP_V6)).andReturn(ImmutableSet.of(OUTER_RELAY_HOST)).anyTimes();
expect(manager.hostService.getHostsByIp(SERVER_IP)).andReturn(ImmutableSet.of(SERVER_HOST)).anyTimes();
expect(manager.hostService.getHostsByIp(SERVER_IP_V6)).andReturn(ImmutableSet.of(SERVER_HOST)).anyTimes();
expect(manager.hostService.getHostsByIp(GATEWAY_IP)).andReturn(ImmutableSet.of(SERVER_HOST)).anyTimes();
expect(manager.hostService.getHostsByIp(GATEWAY_IP_V6)).andReturn(ImmutableSet.of(SERVER_HOST)).anyTimes();
expect(manager.hostService.getHostsByIp(CLIENT_LL_IP_V6)).andReturn(ImmutableSet.of(EXISTS_HOST)).anyTimes();
expect(manager.hostService.getHost(OUTER_RELAY_HOST_ID)).andReturn(OUTER_RELAY_HOST).anyTimes();
packetService = new MockPacketService();
manager.packetService = packetService;
manager.compCfgService = createNiceMock(ComponentConfigService.class);
deviceService = createNiceMock(DeviceService.class);
Device device = createNiceMock(Device.class);
expect(device.is(Pipeliner.class)).andReturn(true).anyTimes();
expect(deviceService.getDevice(DEV_1_ID)).andReturn(device).anyTimes();
expect(deviceService.getDevice(DEV_2_ID)).andReturn(device).anyTimes();
replay(deviceService, device);
mockRouteStore = new MockRouteStore();
mockDhcpRelayStore = new MockDhcpRelayStore();
mockDhcpRelayCountersStore = new MockDhcpRelayCountersStore();
manager.dhcpRelayStore = mockDhcpRelayStore;
manager.deviceService = deviceService;
manager.interfaceService = new MockInterfaceService();
flowObjectiveService = EasyMock.niceMock(FlowObjectiveService.class);
mockHostProviderService = createNiceMock(HostProviderService.class);
v4Handler = new Dhcp4HandlerImpl();
v4Handler.providerService = mockHostProviderService;
v4Handler.dhcpRelayStore = mockDhcpRelayStore;
v4Handler.hostService = manager.hostService;
v4Handler.interfaceService = manager.interfaceService;
v4Handler.packetService = manager.packetService;
v4Handler.routeStore = mockRouteStore;
v4Handler.coreService = createNiceMock(CoreService.class);
v4Handler.flowObjectiveService = flowObjectiveService;
v4Handler.appId = TestApplicationId.create(Dhcp4HandlerImpl.DHCP_V4_RELAY_APP);
v4Handler.deviceService = deviceService;
manager.v4Handler = v4Handler;
v6Handler = new Dhcp6HandlerImpl();
v6Handler.dhcpRelayStore = mockDhcpRelayStore;
v6Handler.dhcpRelayCountersStore = mockDhcpRelayCountersStore;
v6Handler.hostService = manager.hostService;
v6Handler.interfaceService = manager.interfaceService;
v6Handler.packetService = manager.packetService;
v6Handler.routeStore = mockRouteStore;
v6Handler.providerService = mockHostProviderService;
v6Handler.coreService = createNiceMock(CoreService.class);
v6Handler.flowObjectiveService = flowObjectiveService;
v6Handler.appId = TestApplicationId.create(Dhcp6HandlerImpl.DHCP_V6_RELAY_APP);
v6Handler.deviceService = deviceService;
manager.v6Handler = v6Handler;
// properties
Dictionary<String, Object> dictionary = createNiceMock(Dictionary.class);
expect(dictionary.get("arpEnabled")).andReturn(true).anyTimes();
expect(dictionary.get("dhcpPollInterval")).andReturn(120).anyTimes();
ComponentContext context = createNiceMock(ComponentContext.class);
expect(context.getProperties()).andReturn(dictionary).anyTimes();
replay(manager.cfgService, manager.coreService, manager.hostService, manager.compCfgService, dictionary, context);
manager.activate(context);
}
Aggregations