Search in sources :

Example 1 with DeviceConfiguration

use of org.onosproject.segmentrouting.DeviceConfiguration in project trellis-control by opennetworkinglab.

the class DeviceConfigurationTest method setUp.

@Before
public void setUp() throws Exception {
    InterfaceService interfaceService;
    networkConfigService = null;
    NeighbourResolutionService neighbourResolutionService;
    SegmentRoutingManager srManager;
    // Mock device netcfg
    InputStream jsonStream = SegmentRoutingDeviceConfigTest.class.getResourceAsStream("/device.json");
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode = mapper.readTree(jsonStream);
    SegmentRoutingDeviceConfig srDevConfig = new SegmentRoutingDeviceConfig();
    srDevConfig.init(DEV1, CONFIG_KEY, jsonNode, mapper, config -> {
    });
    BasicDeviceConfig basicDeviceConfig = new BasicDeviceConfig();
    basicDeviceConfig.init(DEV1, DEV1.toString(), JsonNodeFactory.instance.objectNode(), mapper, config -> {
    });
    // Mock interface netcfg
    jsonStream = InterfaceConfig.class.getResourceAsStream("/interface1.json");
    jsonNode = mapper.readTree(jsonStream);
    InterfaceConfig interfaceConfig1 = new InterfaceConfig();
    interfaceConfig1.init(CP1, CONFIG_KEY, jsonNode, mapper, config -> {
    });
    jsonStream = InterfaceConfig.class.getResourceAsStream("/interface2.json");
    jsonNode = mapper.readTree(jsonStream);
    InterfaceConfig interfaceConfig2 = new InterfaceConfig();
    interfaceConfig2.init(CP1, CONFIG_KEY, jsonNode, mapper, config -> {
    });
    jsonStream = BasicHostConfig.class.getResourceAsStream("/host1.json");
    jsonNode = mapper.readTree(jsonStream);
    BasicHostConfig hostConfig1 = new BasicHostConfig();
    hostConfig1.init(ROUTER_HOST, "basic", jsonNode, mapper, config -> {
    });
    networkConfigService = createMock(NetworkConfigRegistry.class);
    expect(networkConfigService.getSubjects(DeviceId.class, SegmentRoutingDeviceConfig.class)).andReturn(Sets.newHashSet(DEV1)).anyTimes();
    expect(networkConfigService.getConfig(DEV1, SegmentRoutingDeviceConfig.class)).andReturn(srDevConfig).anyTimes();
    expect(networkConfigService.addConfig(DEV1, BasicDeviceConfig.class)).andReturn(basicDeviceConfig).anyTimes();
    expect(networkConfigService.getConfig(DEV1, BasicDeviceConfig.class)).andReturn(basicDeviceConfig).anyTimes();
    expect(networkConfigService.getSubjects(ConnectPoint.class, InterfaceConfig.class)).andReturn(Sets.newHashSet(CP1, CP2)).anyTimes();
    expect(networkConfigService.getConfig(CP1, InterfaceConfig.class)).andReturn(interfaceConfig1).anyTimes();
    expect(networkConfigService.getConfig(CP2, InterfaceConfig.class)).andReturn(interfaceConfig2).anyTimes();
    expect(networkConfigService.applyConfig(eq(CP1), eq(InterfaceConfig.class), anyObject())).andReturn(interfaceConfig1).anyTimes();
    expect(networkConfigService.applyConfig(eq(CP2), eq(InterfaceConfig.class), anyObject())).andReturn(interfaceConfig2).anyTimes();
    expect(networkConfigService.getConfig(null, SegmentRoutingAppConfig.class)).andReturn(null).anyTimes();
    expect(networkConfigService.getConfig(ROUTER_HOST, BasicHostConfig.class)).andReturn(hostConfig1).anyTimes();
    expect(networkConfigService.applyConfig(eq(ROUTER_HOST), eq(BasicHostConfig.class), anyObject())).andReturn(hostConfig1).anyTimes();
    replay(networkConfigService);
    interfaceService = createMock(InterfaceService.class);
    expect(interfaceService.getInterfaces()).andReturn(INTERFACES).anyTimes();
    expect(interfaceService.getInterfacesByPort(CP1)).andReturn(Sets.newHashSet(INTF1)).anyTimes();
    expect(interfaceService.getInterfacesByPort(CP2)).andReturn(Sets.newHashSet(INTF2)).anyTimes();
    replay(interfaceService);
    neighbourResolutionService = createMock(NeighbourResolutionService.class);
    neighbourResolutionService.registerNeighbourHandler(anyObject(ConnectPoint.class), anyObject(), anyObject());
    expectLastCall().anyTimes();
    replay(neighbourResolutionService);
    srManager = new SegmentRoutingManager();
    srManager.interfaceService = interfaceService;
    srManager.cfgService = networkConfigService;
    srManager.neighbourResolutionService = neighbourResolutionService;
    devConfig = new DeviceConfiguration(srManager);
    devConfig.addSubnet(CP2, ROUTE1);
}
Also used : InputStream(java.io.InputStream) DeviceId(org.onosproject.net.DeviceId) JsonNode(com.fasterxml.jackson.databind.JsonNode) ConnectPoint(org.onosproject.net.ConnectPoint) BasicDeviceConfig(org.onosproject.net.config.basics.BasicDeviceConfig) BasicHostConfig(org.onosproject.net.config.basics.BasicHostConfig) InterfaceConfig(org.onosproject.net.config.basics.InterfaceConfig) InterfaceService(org.onosproject.net.intf.InterfaceService) NetworkConfigRegistry(org.onosproject.net.config.NetworkConfigRegistry) SegmentRoutingManager(org.onosproject.segmentrouting.SegmentRoutingManager) DeviceConfiguration(org.onosproject.segmentrouting.DeviceConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) NeighbourResolutionService(org.onosproject.net.neighbour.NeighbourResolutionService) Before(org.junit.Before)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InputStream (java.io.InputStream)1 Before (org.junit.Before)1 ConnectPoint (org.onosproject.net.ConnectPoint)1 DeviceId (org.onosproject.net.DeviceId)1 NetworkConfigRegistry (org.onosproject.net.config.NetworkConfigRegistry)1 BasicDeviceConfig (org.onosproject.net.config.basics.BasicDeviceConfig)1 BasicHostConfig (org.onosproject.net.config.basics.BasicHostConfig)1 InterfaceConfig (org.onosproject.net.config.basics.InterfaceConfig)1 InterfaceService (org.onosproject.net.intf.InterfaceService)1 NeighbourResolutionService (org.onosproject.net.neighbour.NeighbourResolutionService)1 DeviceConfiguration (org.onosproject.segmentrouting.DeviceConfiguration)1 SegmentRoutingManager (org.onosproject.segmentrouting.SegmentRoutingManager)1