Search in sources :

Example 6 with SegmentRoutingDeviceConfig

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

the class PolicyManager method getEdgeDeviceIds.

private List<DeviceId> getEdgeDeviceIds() {
    List<DeviceId> edges = new ArrayList<>();
    deviceService.getDevices().forEach((device) -> {
        DeviceId deviceId = device.id();
        SegmentRoutingDeviceConfig srDevCfg = cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class);
        if (srDevCfg != null && srDevCfg.isEdgeRouter()) {
            edges.add(deviceId);
        }
    });
    return edges;
}
Also used : SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) DeviceId(org.onosproject.net.DeviceId) ArrayList(java.util.ArrayList)

Example 7 with SegmentRoutingDeviceConfig

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

the class XconnectManager method addOrUpdateXconnect.

@Override
public void addOrUpdateXconnect(DeviceId deviceId, VlanId vlanId, Set<XconnectEndpoint> endpoints) {
    log.info("Adding or updating xconnect. deviceId={}, vlanId={}, endpoints={}", deviceId, vlanId, endpoints);
    SegmentRoutingDeviceConfig config = cfgService.getConfig(deviceId, SegmentRoutingDeviceConfig.class);
    List<PortNumber> devicePorts = deviceService.getPorts(deviceId).stream().map(Port::number).collect(Collectors.toList());
    if (!config.isEdgeRouter()) {
        throw new IllegalArgumentException(ERROR_NOT_EDGE_ROUTER);
    } else {
        Iterator<XconnectEndpoint> itr = endpoints.iterator();
        while (itr.hasNext()) {
            XconnectEndpoint ep = itr.next();
            // Note: we don't validate an endpoint with LOAD_BALANCER type
            if (ep.type() != XconnectEndpoint.Type.PORT) {
                continue;
            }
            if (!devicePorts.contains(((XconnectPortEndpoint) ep).port())) {
                throw new IllegalArgumentException(ERROR_PORT_NOT_RANGE);
            }
        }
    }
    final XconnectKey key = new XconnectKey(deviceId, vlanId);
    xconnectStore.put(key, endpoints);
}
Also used : SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) XconnectPortEndpoint(org.onosproject.segmentrouting.xconnect.api.XconnectPortEndpoint) XconnectEndpoint(org.onosproject.segmentrouting.xconnect.api.XconnectEndpoint) PortNumber(org.onosproject.net.PortNumber) XconnectKey(org.onosproject.segmentrouting.xconnect.api.XconnectKey)

Example 8 with SegmentRoutingDeviceConfig

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

the class RouteHandlerTest method setUp.

@Before
public void setUp() {
    ObjectMapper mapper = new ObjectMapper();
    ConfigApplyDelegate delegate = config -> {
    };
    SegmentRoutingDeviceConfig dev1Config = new SegmentRoutingDeviceConfig();
    JsonNode dev1Tree = mapper.createObjectNode();
    dev1Config.init(CP1.deviceId(), "host-handler-test", dev1Tree, mapper, delegate);
    dev1Config.setPairDeviceId(CP2.deviceId()).setPairLocalPort(P9);
    SegmentRoutingDeviceConfig dev2Config = new SegmentRoutingDeviceConfig();
    JsonNode dev2Tree = mapper.createObjectNode();
    dev2Config.init(CP2.deviceId(), "host-handler-test", dev2Tree, mapper, delegate);
    dev2Config.setPairDeviceId(CP1.deviceId()).setPairLocalPort(P9);
    MockNetworkConfigRegistry mockNetworkConfigRegistry = new MockNetworkConfigRegistry();
    mockNetworkConfigRegistry.applyConfig(dev1Config);
    mockNetworkConfigRegistry.applyConfig(dev2Config);
    // Initialize Segment Routing Manager
    srManager = new MockSegmentRoutingManager(NEXT_TABLE, ROUTER_MACS);
    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 = createMock(DeviceConfiguration.class);
    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);
    hostService = new MockHostService(HOSTS);
    srManager.hostService = hostService;
    srManager.cfgService = mockNetworkConfigRegistry;
    srManager.routeService = new MockRouteService(ROUTE_STORE);
    srManager.phasedRecoveryService = createMock(PhasedRecoveryService.class);
    expect(srManager.phasedRecoveryService.isEnabled()).andReturn(true).anyTimes();
    replay(srManager.phasedRecoveryService);
    routeHandler = new RouteHandler(srManager);
    ROUTING_TABLE.clear();
    BRIDGING_TABLE.clear();
    SUBNET_TABLE.clear();
}
Also used : Route(org.onosproject.routeservice.Route) HostLocation(org.onosproject.net.HostLocation) Host(org.onosproject.net.Host) Interface(org.onosproject.net.intf.Interface) PortNumber(org.onosproject.net.PortNumber) RouteEvent(org.onosproject.routeservice.RouteEvent) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) HostService(org.onosproject.net.host.HostService) ConnectPoint(org.onosproject.net.ConnectPoint) DefaultHost(org.onosproject.net.DefaultHost) Lists(com.google.common.collect.Lists) StorageService(org.onosproject.store.service.StorageService) EasyMock.reset(org.easymock.EasyMock.reset) Map(java.util.Map) PhasedRecoveryService(org.onosproject.segmentrouting.phasedrecovery.api.PhasedRecoveryService) JsonNode(com.fasterxml.jackson.databind.JsonNode) NetworkConfigRegistryAdapter(org.onosproject.net.config.NetworkConfigRegistryAdapter) 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) TestConsistentMap(org.onosproject.store.service.TestConsistentMap) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) TestConsistentMultimap(org.onosproject.store.service.TestConsistentMultimap) EasyMock.expect(org.easymock.EasyMock.expect) Maps(com.google.common.collect.Maps) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) Sets(com.google.common.collect.Sets) EasyMock.expectLastCall(org.easymock.EasyMock.expectLastCall) List(java.util.List) MacAddress(org.onlab.packet.MacAddress) DeviceId(org.onosproject.net.DeviceId) ResolvedRoute(org.onosproject.routeservice.ResolvedRoute) Assert(org.junit.Assert) EasyMock.verify(org.easymock.EasyMock.verify) IpPrefix(org.onlab.packet.IpPrefix) SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) JsonNode(com.fasterxml.jackson.databind.JsonNode) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) StorageService(org.onosproject.store.service.StorageService) PhasedRecoveryService(org.onosproject.segmentrouting.phasedrecovery.api.PhasedRecoveryService) NetworkConfigRegistryAdapter(org.onosproject.net.config.NetworkConfigRegistryAdapter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 9 with SegmentRoutingDeviceConfig

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

the class FabricIntProgrammable method getSidForCollector.

/**
 * Gets the SID of the device which collector attached to.
 * TODO: remove this method once we get SR API done.
 *
 * @param collectorIp the IP address of the INT collector
 * @return the SID of the device, Optional.empty() if we cannot find the SID of
 *         the device
 */
private Optional<Integer> getSidForCollector(IpAddress collectorIp) {
    Set<Host> collectorHosts = hostService.getHostsByIp(collectorIp);
    if (collectorHosts.isEmpty()) {
        log.warn("Unable to find collector with IP {}, skip for now.", collectorIp);
        return Optional.empty();
    }
    Host collector = collectorHosts.iterator().next();
    if (collectorHosts.size() > 1) {
        log.warn("Find more than one host with IP {}, will use {} as collector.", collectorIp, collector.id());
    }
    Set<HostLocation> locations = collector.locations();
    if (locations.isEmpty()) {
        log.warn("Unable to find the location of collector {}, skip for now.", collector.id());
        return Optional.empty();
    }
    HostLocation location = locations.iterator().next();
    if (locations.size() > 1) {
        // TODO: revisit this when we want to support dual-homed INT collector.
        log.warn("Find more than one location for host {}, will use {}", collector.id(), location);
    }
    DeviceId deviceWithCollector = location.deviceId();
    SegmentRoutingDeviceConfig cfg = cfgService.getConfig(deviceWithCollector, SegmentRoutingDeviceConfig.class);
    if (cfg == null) {
        log.error("Missing SegmentRoutingDeviceConfig config for {}, " + "cannot derive SID for collector", deviceWithCollector);
        return Optional.empty();
    }
    if (cfg.nodeSidIPv4() == -1) {
        log.error("Missing ipv4NodeSid in segment routing config for device {}", deviceWithCollector);
        return Optional.empty();
    }
    return Optional.of(cfg.nodeSidIPv4());
}
Also used : SegmentRoutingDeviceConfig(org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig) DeviceId(org.onosproject.net.DeviceId) HostLocation(org.onosproject.net.HostLocation) Host(org.onosproject.net.Host)

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