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);
});
}
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();
}
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);
}
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);
}
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;
}
Aggregations