use of org.onosproject.dhcprelay.config.IgnoreDhcpConfig 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.dhcprelay.config.IgnoreDhcpConfig 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.dhcprelay.config.IgnoreDhcpConfig 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.dhcprelay.config.IgnoreDhcpConfig 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.dhcprelay.config.IgnoreDhcpConfig in project onos by opennetworkinglab.
the class DhcpRelayManager method updateConfig.
/**
* Updates DHCP relay app configuration with given configuration.
*
* @param config the configuration ot update
*/
protected void updateConfig(Config config) {
if (config instanceof IndirectDhcpRelayConfig) {
IndirectDhcpRelayConfig indirectConfig = (IndirectDhcpRelayConfig) config;
v4Handler.setIndirectDhcpServerConfigs(indirectConfig.dhcpServerConfigs());
v6Handler.setIndirectDhcpServerConfigs(indirectConfig.dhcpServerConfigs());
} else if (config instanceof DefaultDhcpRelayConfig) {
DefaultDhcpRelayConfig defaultConfig = (DefaultDhcpRelayConfig) config;
v4Handler.setDefaultDhcpServerConfigs(defaultConfig.dhcpServerConfigs());
v6Handler.setDefaultDhcpServerConfigs(defaultConfig.dhcpServerConfigs());
}
if (config instanceof IgnoreDhcpConfig) {
v4Handler.updateIgnoreVlanConfig((IgnoreDhcpConfig) config);
v6Handler.updateIgnoreVlanConfig((IgnoreDhcpConfig) config);
}
if (config instanceof HostAutoRelearnConfig) {
setHostAutoRelearnConfig((HostAutoRelearnConfig) config);
}
}
Aggregations