use of org.onosproject.net.flowobjective.FlowObjectiveService in project onos by opennetworkinglab.
the class ControlPlaneRedirectManagerTest method setUp.
@Before
public void setUp() {
networkConfigListener = createMock(NetworkConfigListener.class);
deviceService = new TestDeviceService();
deviceListener = createMock(DeviceListener.class);
interfaceListener = createMock(InterfaceListener.class);
deviceService.addListener(deviceListener);
setUpInterfaceService();
interfaceService = new InternalInterfaceService();
interfaceService.addListener(interfaceListener);
networkConfigService = new TestNetworkConfigService();
networkConfigService.addListener(networkConfigListener);
flowObjectiveService = createMock(FlowObjectiveService.class);
applicationService = createNiceMock(ApplicationService.class);
replay(applicationService);
setUpFlowObjectiveService();
controlPlaneRedirectManager.coreService = coreService;
controlPlaneRedirectManager.flowObjectiveService = flowObjectiveService;
controlPlaneRedirectManager.networkConfigService = networkConfigService;
controlPlaneRedirectManager.interfaceService = interfaceService;
controlPlaneRedirectManager.deviceService = deviceService;
controlPlaneRedirectManager.hostService = createNiceMock(HostService.class);
controlPlaneRedirectManager.mastershipService = mastershipService;
controlPlaneRedirectManager.applicationService = applicationService;
controlPlaneRedirectManager.activate(new ComponentContextAdapter());
verify(flowObjectiveService);
}
use of org.onosproject.net.flowobjective.FlowObjectiveService in project onos by opennetworkinglab.
the class FibInstallerTest method setUp.
@Before
public void setUp() throws Exception {
sSfibInstaller = new FibInstaller();
sSfibInstaller.componentConfigService = createNiceMock(ComponentConfigService.class);
ComponentContext mockContext = createNiceMock(ComponentContext.class);
routerConfig = new TestRouterConfig();
interfaceService = createMock(InterfaceService.class);
networkConfigService = createMock(NetworkConfigService.class);
networkConfigService.addListener(anyObject(NetworkConfigListener.class));
expectLastCall().anyTimes();
networkConfigRegistry = createMock(NetworkConfigRegistry.class);
flowObjectiveService = createMock(FlowObjectiveService.class);
applicationService = createNiceMock(ApplicationService.class);
replay(applicationService);
deviceService = new TestDeviceService();
CoreService coreService = createNiceMock(CoreService.class);
expect(coreService.registerApplication(anyString())).andReturn(APPID).anyTimes();
replay(coreService);
sSfibInstaller.networkConfigService = networkConfigService;
sSfibInstaller.networkConfigRegistry = networkConfigRegistry;
sSfibInstaller.interfaceService = interfaceService;
sSfibInstaller.flowObjectiveService = flowObjectiveService;
sSfibInstaller.applicationService = applicationService;
sSfibInstaller.coreService = coreService;
sSfibInstaller.routeService = new TestRouteService();
sSfibInstaller.deviceService = deviceService;
setUpNetworkConfigService();
setUpInterfaceService();
sSfibInstaller.activate(mockContext);
}
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()));
}
Aggregations