Search in sources :

Example 1 with SegmentRoutingDeviceConfig

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

the class DeviceConfiguration method updateConfig.

public void updateConfig() {
    // Read config from device subject, excluding gatewayIps and subnets.
    Set<DeviceId> deviceSubjects = srManager.cfgService.getSubjects(DeviceId.class, SegmentRoutingDeviceConfig.class);
    deviceSubjects.forEach(subject -> {
        SegmentRoutingDeviceConfig config = srManager.cfgService.getConfig(subject, SegmentRoutingDeviceConfig.class);
        SegmentRouterInfo info = new SegmentRouterInfo();
        info.deviceId = subject;
        info.ipv4NodeSid = config.nodeSidIPv4();
        info.ipv6NodeSid = config.nodeSidIPv6();
        info.ipv4Loopback = config.routerIpv4();
        info.ipv6Loopback = config.routerIpv6();
        info.mac = config.routerMac();
        info.isEdge = config.isEdgeRouter();
        info.adjacencySids = config.adjacencySids();
        info.pairDeviceId = config.pairDeviceId();
        info.pairLocalPort = config.pairLocalPort();
        info.pwRoutingLabel = info.ipv4NodeSid + 1000;
        deviceConfigMap.put(info.deviceId, info);
        log.debug("Read device config for device: {}", info.deviceId);
        // IPv6 sid is not inserted. this part of the code is not used for now.
        allSegmentIds.add(info.ipv4NodeSid);
        // Block host with routerMac and untagged VLAN
        blockHost(info.mac, VlanId.NONE);
    });
    // Read gatewayIps and subnets from port subject. Ignore suppressed ports.
    Set<ConnectPoint> portSubjects = srManager.cfgService.getSubjects(ConnectPoint.class, InterfaceConfig.class);
    portSubjects.stream().filter(subject -> deviceConfigMap.containsKey(subject.deviceId())).filter(subject -> !isSuppressedPort(subject)).forEach(subject -> {
        InterfaceConfig config = srManager.cfgService.getConfig(subject, InterfaceConfig.class);
        Set<Interface> networkInterfaces;
        try {
            networkInterfaces = config.getInterfaces();
        } catch (ConfigException e) {
            log.error("Error loading port configuration");
            return;
        }
        networkInterfaces.forEach(networkInterface -> {
            VlanId vlanId = networkInterface.vlan();
            ConnectPoint connectPoint = networkInterface.connectPoint();
            DeviceId dpid = connectPoint.deviceId();
            PortNumber port = connectPoint.port();
            MacAddress mac = networkInterface.mac();
            SegmentRouterInfo info = deviceConfigMap.get(dpid);
            // skip if there is no corresponding device for this ConnectPoint
            if (info != null) {
                // Extract subnet information
                List<InterfaceIpAddress> interfaceAddresses = networkInterface.ipAddressesList();
                interfaceAddresses.forEach(interfaceAddress -> {
                    // Do not add /0, /32 and /128 to gateway IP list
                    int prefixLength = interfaceAddress.subnetAddress().prefixLength();
                    IpPrefix ipPrefix = interfaceAddress.subnetAddress();
                    if (ipPrefix.isIp4()) {
                        if (prefixLength != 0 && prefixLength != IpPrefix.MAX_INET_MASK_LENGTH) {
                            info.gatewayIps.put(port, interfaceAddress.ipAddress());
                        }
                        info.subnets.put(port, interfaceAddress.subnetAddress());
                    } else {
                        if (prefixLength != 0 && prefixLength != IpPrefix.MAX_INET6_MASK_LENGTH) {
                            info.gatewayIps.put(port, interfaceAddress.ipAddress());
                        }
                        info.subnets.put(port, interfaceAddress.subnetAddress());
                    }
                });
                // Override interface mac with router mac
                if (!mac.equals(info.mac)) {
                    ArrayNode array = (ArrayNode) config.node();
                    for (JsonNode intfNode : array) {
                        ObjectNode objNode = (ObjectNode) intfNode;
                        objNode.put(InterfaceConfig.MAC, info.mac.toString());
                    }
                    srManager.cfgService.applyConfig(connectPoint, InterfaceConfig.class, array);
                }
                // Block host with routerMac and taggedVlan
                networkInterface.vlanTagged().forEach(taggedVlan -> {
                    blockHost(info.mac, taggedVlan);
                });
            }
        });
        // We register the connect point with the NRS.
        srManager.registerConnectPoint(subject);
    });
}
Also used : DeviceConfigNotFoundException(org.onosproject.segmentrouting.config.DeviceConfigNotFoundException) Route(org.onosproject.routeservice.Route) Interface(org.onosproject.net.intf.Interface) PortNumber(org.onosproject.net.PortNumber) InterfaceConfig(org.onosproject.net.config.basics.InterfaceConfig) LoggerFactory(org.slf4j.LoggerFactory) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) HashMap(java.util.HashMap) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Multimaps(com.google.common.collect.Multimaps) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) SegmentRoutingAppConfig(org.onosproject.segmentrouting.config.SegmentRoutingAppConfig) HashMultimap(com.google.common.collect.HashMultimap) Lists(com.google.common.collect.Lists) Map(java.util.Map) BasicHostConfig(org.onosproject.net.config.basics.BasicHostConfig) JsonNode(com.fasterxml.jackson.databind.JsonNode) HostId(org.onosproject.net.HostId) IpAddress(org.onlab.packet.IpAddress) Ip6Address(org.onlab.packet.Ip6Address) ImmutableSet(com.google.common.collect.ImmutableSet) Ip4Address(org.onlab.packet.Ip4Address) Logger(org.slf4j.Logger) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VlanId(org.onlab.packet.VlanId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Collectors(java.util.stream.Collectors) SetMultimap(com.google.common.collect.SetMultimap) Sets(com.google.common.collect.Sets) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) MacAddress(org.onlab.packet.MacAddress) DeviceProperties(org.onosproject.segmentrouting.config.DeviceProperties) DeviceId(org.onosproject.net.DeviceId) ConfigException(org.onosproject.net.config.ConfigException) Collections(java.util.Collections) IpPrefix(org.onlab.packet.IpPrefix) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DeviceId(org.onosproject.net.DeviceId) ConfigException(org.onosproject.net.config.ConfigException) JsonNode(com.fasterxml.jackson.databind.JsonNode) MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) IpPrefix(org.onlab.packet.IpPrefix) InterfaceConfig(org.onosproject.net.config.basics.InterfaceConfig) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) PortNumber(org.onosproject.net.PortNumber) Interface(org.onosproject.net.intf.Interface) VlanId(org.onlab.packet.VlanId) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress)

Example 2 with SegmentRoutingDeviceConfig

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

the class HostHandlerTest method setUp.

@Before
public void setUp() {
    // Initialize pairDevice and pairLocalPort config
    ObjectMapper mapper = new ObjectMapper();
    ConfigApplyDelegate delegate = config -> {
    };
    SegmentRoutingDeviceConfig dev3Config = new SegmentRoutingDeviceConfig();
    JsonNode dev3Tree = mapper.createObjectNode();
    dev3Config.init(DEV3, "host-handler-test", dev3Tree, mapper, delegate);
    dev3Config.setPairDeviceId(DEV4).setPairLocalPort(P9);
    SegmentRoutingDeviceConfig dev4Config = new SegmentRoutingDeviceConfig();
    JsonNode dev4Tree = mapper.createObjectNode();
    dev4Config.init(DEV4, "host-handler-test", dev4Tree, mapper, delegate);
    dev4Config.setPairDeviceId(DEV3).setPairLocalPort(P9);
    MockNetworkConfigRegistry mockNetworkConfigRegistry = new MockNetworkConfigRegistry();
    mockNetworkConfigRegistry.applyConfig(dev3Config);
    mockNetworkConfigRegistry.applyConfig(dev4Config);
    // Initialize Segment Routing Manager
    SegmentRoutingManager srManager = new MockSegmentRoutingManager(NEXT_TABLE, Maps.newHashMap());
    srManager.storageService = createMock(StorageService.class);
    expect(srManager.storageService.consistentMapBuilder()).andReturn(new TestConsistentMap.Builder<>()).anyTimes();
    expect(srManager.storageService.consistentMultimapBuilder()).andReturn(new TestConsistentMultimap.Builder<>()).anyTimes();
    replay(srManager.storageService);
    srManager.cfgService = new NetworkConfigRegistryAdapter();
    srManager.deviceConfiguration = new DeviceConfiguration(srManager);
    srManager.flowObjectiveService = new MockFlowObjectiveService(BRIDGING_TABLE, NEXT_TABLE);
    srManager.routingRulePopulator = new MockRoutingRulePopulator(srManager, ROUTING_TABLE);
    srManager.defaultRoutingHandler = new MockDefaultRoutingHandler(srManager, SUBNET_TABLE, ROUTING_TABLE, LED_DEVICES);
    srManager.interfaceService = new MockInterfaceService(INTERFACES);
    srManager.hostService = new MockHostService(HOSTS);
    srManager.cfgService = mockNetworkConfigRegistry;
    mockLocationProbingService = new MockHostProbingService();
    srManager.probingService = mockLocationProbingService;
    srManager.linkHandler = new MockLinkHandler(srManager);
    // Not important for most of the HostHandler test case. Simply return an empty set here
    srManager.routeService = createNiceMock(RouteService.class);
    expect(srManager.routeService.getRouteTables()).andReturn(Sets.newHashSet()).anyTimes();
    replay(srManager.routeService);
    hostHandler = new HostHandler(srManager);
    hostHandler.hostWorkers = new PredictableExecutor(0, groupedThreads("onos/sr", "h-worker-%d"), true);
    ROUTING_TABLE.clear();
    BRIDGING_TABLE.clear();
}
Also used : Route(org.onosproject.routeservice.Route) HostLocation(org.onosproject.net.HostLocation) PredictableExecutor(org.onlab.util.PredictableExecutor) Interface(org.onosproject.net.intf.Interface) PortNumber(org.onosproject.net.PortNumber) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) ConnectPoint(org.onosproject.net.ConnectPoint) StorageService(org.onosproject.store.service.StorageService) EasyMock.reset(org.easymock.EasyMock.reset) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) NetworkConfigRegistryAdapter(org.onosproject.net.config.NetworkConfigRegistryAdapter) RouteService(org.onosproject.routeservice.RouteService) TestConsistentMap(org.onosproject.store.service.TestConsistentMap) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) Set(java.util.Set) TestConsistentMultimap(org.onosproject.store.service.TestConsistentMultimap) ProbeMode(org.onosproject.net.host.ProbeMode) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Sets(com.google.common.collect.Sets) EthType(org.onlab.packet.EthType) EasyMock.createNiceMock(org.easymock.EasyMock.createNiceMock) RouteInfo(org.onosproject.routeservice.RouteInfo) RouteTableId(org.onosproject.routeservice.RouteTableId) DeviceId(org.onosproject.net.DeviceId) IpPrefix(org.onlab.packet.IpPrefix) Host(org.onosproject.net.Host) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) CompletableFuture(java.util.concurrent.CompletableFuture) DefaultHost(org.onosproject.net.DefaultHost) Lists(com.google.common.collect.Lists) HostProbingService(org.onosproject.net.host.HostProbingService) HostEvent(org.onosproject.net.host.HostEvent) EasyMock.replay(org.easymock.EasyMock.replay) EasyMock.createMock(org.easymock.EasyMock.createMock) HostId(org.onosproject.net.HostId) Before(org.junit.Before) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) EasyMock(org.easymock.EasyMock) EasyMock.expect(org.easymock.EasyMock.expect) Maps(com.google.common.collect.Maps) EasyMock.expectLastCall(org.easymock.EasyMock.expectLastCall) MacAddress(org.onlab.packet.MacAddress) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) EasyMock.verify(org.easymock.EasyMock.verify) Assert(org.junit.Assert) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) PredictableExecutor(org.onlab.util.PredictableExecutor) JsonNode(com.fasterxml.jackson.databind.JsonNode) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) StorageService(org.onosproject.store.service.StorageService) NetworkConfigRegistryAdapter(org.onosproject.net.config.NetworkConfigRegistryAdapter) RouteService(org.onosproject.routeservice.RouteService) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 3 with SegmentRoutingDeviceConfig

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

the class IcmpHandlerTest method setUp.

@Before
public void setUp() {
    // Init
    ObjectMapper mapper = new ObjectMapper();
    ConfigApplyDelegate delegate = config -> {
    };
    // Setup configuration for app
    SegmentRoutingAppConfig appConfig = new SegmentRoutingAppConfig();
    JsonNode appTree = mapper.createObjectNode();
    appConfig.init(testApplicationId, "icmp-handler-test", appTree, mapper, delegate);
    appConfig.setSuppressSubnet(Collections.emptySet());
    // Setup configuration for the devices
    SegmentRoutingDeviceConfig remoteLeafConfig = new SegmentRoutingDeviceConfig();
    JsonNode remoteLeafTree = mapper.createObjectNode();
    remoteLeafConfig.init(REMOTE_LEAF, "icmp-handler-test", remoteLeafTree, mapper, delegate);
    remoteLeafConfig.setNodeSidIPv4(REMOTE_LEAF_SID4).setNodeSidIPv6(REMOTE_LEAF_SID6).setRouterIpv4(REMOTE_LEAF_LB4).setRouterIpv6(REMOTE_LEAF_LB6).setIsEdgeRouter(true).setRouterMac(REMOTE_MAC.toString());
    SegmentRoutingDeviceConfig localLeafConfig = new SegmentRoutingDeviceConfig();
    JsonNode localLeafTree = mapper.createObjectNode();
    localLeafConfig.init(LOCAL_LEAF, "icmp-handler-test", localLeafTree, mapper, delegate);
    localLeafConfig.setNodeSidIPv4(LOCAL_LEAF_SID4).setRouterIpv4(LOCAL_LEAF_LB4).setNodeSidIPv6(LOCAL_LEAF_SID6).setRouterIpv6(LOCAL_LEAF_LB6).setIsEdgeRouter(true).setRouterMac(LOCAL_MAC.toString());
    SegmentRoutingDeviceConfig localLeaf1Config = new SegmentRoutingDeviceConfig();
    JsonNode localLeaf1Tree = mapper.createObjectNode();
    localLeaf1Config.init(LOCAL_LEAF1, "icmp-handler-test", localLeaf1Tree, mapper, delegate);
    localLeaf1Config.setNodeSidIPv4(LOCAL_LEAF1_SID4).setRouterIpv4(LOCAL_LEAF1_LB4).setNodeSidIPv6(LOCAL_LEAF1_SID6).setRouterIpv6(LOCAL_LEAF1_LB6).setIsEdgeRouter(true).setRouterMac(LOCAL_MAC1.toString()).setPairDeviceId(LOCAL_LEAF2).setPairLocalPort(P3);
    SegmentRoutingDeviceConfig localLeaf2Config = new SegmentRoutingDeviceConfig();
    JsonNode localLeaf2Tree = mapper.createObjectNode();
    localLeaf2Config.init(LOCAL_LEAF2, "icmp-handler-test", localLeaf2Tree, mapper, delegate);
    localLeaf2Config.setNodeSidIPv4(LOCAL_LEAF2_SID4).setRouterIpv4(LOCAL_LEAF2_LB4).setNodeSidIPv6(LOCAL_LEAF2_SID6).setRouterIpv6(LOCAL_LEAF2_LB6).setIsEdgeRouter(true).setRouterMac(LOCAL_MAC2.toString()).setPairDeviceId(LOCAL_LEAF1).setPairLocalPort(P3);
    // Setup configuration for ports
    InterfaceConfig remoteLeafPorts1Config = new InterfaceConfig();
    ArrayNode remoteLeafPorts1Tree = mapper.createArrayNode();
    remoteLeafPorts1Config.init(CP12, "icmp-handler-test", remoteLeafPorts1Tree, mapper, delegate);
    remoteLeafPorts1Config.addInterface(INTF1);
    InterfaceConfig remoteLeafPorts2Config = new InterfaceConfig();
    ArrayNode remoteLeafPorts2Tree = mapper.createArrayNode();
    remoteLeafPorts2Config.init(CP13, "icmp-handler-test", remoteLeafPorts2Tree, mapper, delegate);
    remoteLeafPorts2Config.addInterface(INTF2);
    InterfaceConfig localLeafPortsConfig = new InterfaceConfig();
    ArrayNode localLeafPortsTree = mapper.createArrayNode();
    localLeafPortsConfig.init(CP1011, "icmp-handler-test", localLeafPortsTree, mapper, delegate);
    localLeafPortsConfig.addInterface(INTF111);
    InterfaceConfig localLeaf1PortsConfig = new InterfaceConfig();
    ArrayNode localLeaf1PortsTree = mapper.createArrayNode();
    localLeaf1PortsConfig.init(CP2011, "icmp-handler-test", localLeaf1PortsTree, mapper, delegate);
    localLeaf1PortsConfig.addInterface(INTF211);
    InterfaceConfig localLeaf2Ports1Config = new InterfaceConfig();
    ArrayNode localLeaf2Ports1Tree = mapper.createArrayNode();
    localLeaf2Ports1Config.init(CP2021, "icmp-handler-test", localLeaf2Ports1Tree, mapper, delegate);
    localLeaf2Ports1Config.addInterface(INTF212);
    InterfaceConfig localLeaf2Ports2Config = new InterfaceConfig();
    ArrayNode localLeaf2Ports2Tree = mapper.createArrayNode();
    localLeaf2Ports2Config.init(CP2024, "icmp-handler-test", localLeaf2Ports2Tree, mapper, delegate);
    localLeaf2Ports2Config.addInterface(INTF213);
    // Apply config
    MockNetworkConfigRegistry mockNetworkConfigRegistry = new MockNetworkConfigRegistry();
    mockNetworkConfigRegistry.applyConfig(remoteLeafConfig);
    mockNetworkConfigRegistry.applyConfig(remoteLeafPorts1Config);
    mockNetworkConfigRegistry.applyConfig(remoteLeafPorts2Config);
    mockNetworkConfigRegistry.applyConfig(localLeafConfig);
    mockNetworkConfigRegistry.applyConfig(localLeafPortsConfig);
    mockNetworkConfigRegistry.applyConfig(localLeaf1Config);
    mockNetworkConfigRegistry.applyConfig(localLeaf1PortsConfig);
    mockNetworkConfigRegistry.applyConfig(localLeaf2Config);
    mockNetworkConfigRegistry.applyConfig(localLeaf2Ports1Config);
    mockNetworkConfigRegistry.applyConfig(localLeaf2Ports2Config);
    segmentRoutingManager = new SegmentRoutingManager();
    segmentRoutingManager.appId = testApplicationId;
    packetService = new MockPacketService();
    segmentRoutingManager.packetService = packetService;
    segmentRoutingManager.cfgService = mockNetworkConfigRegistry;
    segmentRoutingManager.neighbourResolutionService = new MockNeighbourResolutionService();
    segmentRoutingManager.interfaceService = new MockInterfaceService(ImmutableSet.of(INTF1, INTF2, INTF111, INTF211, INTF212, INTF213));
    segmentRoutingManager.deviceConfiguration = new DeviceConfiguration(segmentRoutingManager);
    segmentRoutingManager.ipHandler = new IpHandler(segmentRoutingManager);
    segmentRoutingManager.deviceService = createMock(DeviceService.class);
    segmentRoutingManager.routeService = new MockRouteService(ROUTE_STORE);
    segmentRoutingManager.hostService = new MockHostService(Collections.emptySet());
    icmpHandler = new IcmpHandler(segmentRoutingManager);
}
Also used : ICMP6(org.onlab.packet.ICMP6) TestApplicationId(org.onosproject.TestApplicationId) InterfaceConfig(org.onosproject.net.config.basics.InterfaceConfig) DeviceService(org.onosproject.net.device.DeviceService) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) Ethernet(org.onlab.packet.Ethernet) SegmentRoutingAppConfig(org.onosproject.segmentrouting.config.SegmentRoutingAppConfig) ApplicationId(org.onosproject.core.ApplicationId) Is.is(org.hamcrest.core.Is.is) JsonNode(com.fasterxml.jackson.databind.JsonNode) Before(org.junit.Before) ImmutableSet(com.google.common.collect.ImmutableSet) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) ICMP(org.onlab.packet.ICMP) EasyMock(org.easymock.EasyMock) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IPv6(org.onlab.packet.IPv6) IPv4(org.onlab.packet.IPv4) ECHO_REPLY(org.onlab.packet.ICMP6.ECHO_REPLY) MPLS(org.onlab.packet.MPLS) Assert(org.junit.Assert) TestUtils(org.onosproject.segmentrouting.TestUtils) Collections(java.util.Collections) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) SegmentRoutingAppConfig(org.onosproject.segmentrouting.config.SegmentRoutingAppConfig) DeviceService(org.onosproject.net.device.DeviceService) JsonNode(com.fasterxml.jackson.databind.JsonNode) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) InterfaceConfig(org.onosproject.net.config.basics.InterfaceConfig) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 4 with SegmentRoutingDeviceConfig

use of org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig in project fabric-tna by stratum.

the class SlicingManagerTest method setup.

@Before
public void setup() {
    SLICE_IDS.clear();
    SLICE_IDS.add(SliceId.DEFAULT);
    SLICE_IDS.add(SliceId.of(1));
    SLICE_IDS.add(SliceId.of(2));
    SLICE_IDS.add(SliceId.of(3));
    SLICE_IDS.add(SliceId.of(4));
    DEVICES.clear();
    DEVICES.add(new MockDevice(DEVICE_ID, null));
    String pipeconfId = "mock_pipeconf";
    MockPiPipelineModel pipelineModel = new MockPiPipelineModel(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), TNA);
    MockPipeconf mockPipeconf = new MockPipeconf(new PiPipeconfId(pipeconfId), pipelineModel);
    manager.appId = APP_ID;
    manager.coreService = coreService;
    manager.storageService = storageService;
    manager.flowRuleService = flowRuleService;
    manager.deviceService = deviceService;
    manager.workPartitionService = workPartitionService;
    manager.codecService = codecService;
    manager.networkCfgService = nwCfgService;
    manager.pipeconfService = pipeconfService;
    EasyMock.expect(coreService.registerApplication(EasyMock.anyObject(), EasyMock.anyObject())).andReturn(APP_ID);
    EasyMock.expect(storageService.<SliceStoreKey, TrafficClassDescription>consistentMapBuilder()).andReturn(new MockConsistentMap.Builder<>());
    EasyMock.expect(storageService.<TrafficSelector, SliceStoreKey>consistentMapBuilder()).andReturn(new MockConsistentMap.Builder<>());
    EasyMock.expect(storageService.<SliceId, TrafficClass>consistentMapBuilder()).andReturn(new MockConsistentMap.Builder<>());
    EasyMock.expect(workPartitionService.isMine(EasyMock.anyObject(), EasyMock.anyObject())).andReturn(true).anyTimes();
    EasyMock.expect(deviceService.getAvailableDevices()).andReturn(DEVICES).anyTimes();
    EasyMock.expect(nwCfgService.getConfig(EasyMock.anyObject(), EasyMock.eq(SegmentRoutingDeviceConfig.class))).andReturn(new SegmentRoutingDeviceConfig() {

        @Override
        public Boolean isEdgeRouter() {
            return true;
        }
    }).anyTimes();
    deviceService.addListener(EasyMock.anyObject());
    EasyMock.expectLastCall();
    flowRuleService.applyFlowRules(EasyMock.capture(capturedAddedFlowRules));
    EasyMock.expectLastCall().anyTimes();
    flowRuleService.removeFlowRules(EasyMock.capture(capturedRemovedFlowRules));
    EasyMock.expectLastCall().anyTimes();
    codecService.registerCodec(EasyMock.anyObject(), EasyMock.anyObject());
    EasyMock.expectLastCall().times(2);
    EasyMock.expect(pipeconfService.getPipeconf(DEVICE_ID)).andReturn(Optional.of(mockPipeconf)).anyTimes();
    EasyMock.replay(coreService, storageService, workPartitionService, deviceService, flowRuleService, codecService, nwCfgService, pipeconfService);
    manager.activate();
    EasyMock.verify(coreService, storageService, workPartitionService, deviceService, flowRuleService, codecService, nwCfgService, pipeconfService);
}
Also used : SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) PiPipeconfId(org.onosproject.net.pi.model.PiPipeconfId) TrafficClass(org.stratumproject.fabric.tna.slicing.api.TrafficClass) SliceId(org.stratumproject.fabric.tna.slicing.api.SliceId) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) TrafficClassDescription(org.stratumproject.fabric.tna.slicing.api.TrafficClassDescription) MockPiPipelineModel(org.stratumproject.fabric.tna.behaviour.upf.MockPiPipelineModel) Before(org.junit.Before)

Example 5 with SegmentRoutingDeviceConfig

use of org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig in project fabric-tna by stratum.

the class TestUtils method getSrConfig.

public static SegmentRoutingDeviceConfig getSrConfig(DeviceId deviceId, String filename) {
    SegmentRoutingDeviceConfig srCfg = new SegmentRoutingDeviceConfig();
    InputStream jsonStream = TestUtils.class.getResourceAsStream(filename);
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonNode;
    try {
        jsonNode = mapper.readTree(jsonStream);
        srCfg.init(deviceId, SR_CONFIG_KEY, jsonNode, mapper, config -> {
        });
    } catch (IOException e) {
        fail("Got error when reading file " + filename + " : " + e.getMessage());
    }
    return srCfg;
}
Also used : SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) InputStream(java.io.InputStream) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

SegmentRoutingDeviceConfig (org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 DeviceId (org.onosproject.net.DeviceId)5 Before (org.junit.Before)4 PortNumber (org.onosproject.net.PortNumber)4 Lists (com.google.common.collect.Lists)3 Sets (com.google.common.collect.Sets)3 Map (java.util.Map)3 Set (java.util.Set)3 Assert (org.junit.Assert)3 Test (org.junit.Test)3 IpAddress (org.onlab.packet.IpAddress)3 IpPrefix (org.onlab.packet.IpPrefix)3 MacAddress (org.onlab.packet.MacAddress)3 VlanId (org.onlab.packet.VlanId)3 ConnectPoint (org.onosproject.net.ConnectPoint)3 HostId (org.onosproject.net.HostId)3 ConfigApplyDelegate (org.onosproject.net.config.ConfigApplyDelegate)3 InterfaceIpAddress (org.onosproject.net.host.InterfaceIpAddress)3