use of org.onosproject.segmentrouting.config.SegmentRoutingAppConfig 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.SegmentRoutingAppConfig in project trellis-control by opennetworkinglab.
the class AppConfigHandler method processAppConfigUpdated.
/**
* Processes Segment Routing App Config updated event.
*
* @param event network config updated event
*/
protected void processAppConfigUpdated(NetworkConfigEvent event) {
log.info("Processing AppConfig CONFIG_UPDATED");
SegmentRoutingAppConfig config = (SegmentRoutingAppConfig) event.config().get();
SegmentRoutingAppConfig prevConfig = (SegmentRoutingAppConfig) event.prevConfig().get();
deviceService.getAvailableDevices().forEach(device -> {
Set<MacAddress> macAddresses = new HashSet<>(getMacAddresses(config));
Set<MacAddress> prevMacAddresses = new HashSet<>(getMacAddresses(prevConfig));
// Avoid removing and re-adding unchanged MAC addresses since
// FlowObjective does not guarantee the execution order.
Set<MacAddress> sameMacAddresses = new HashSet<>(macAddresses);
sameMacAddresses.retainAll(prevMacAddresses);
macAddresses.removeAll(sameMacAddresses);
prevMacAddresses.removeAll(sameMacAddresses);
revokeVRouter(device.id(), prevMacAddresses);
populateVRouter(device.id(), macAddresses);
Set<IpPrefix> toRemove = Sets.difference(prevConfig.blackholeIPs(), config.blackholeIPs());
toRemove.forEach(ipPrefix -> {
srManager.routingRulePopulator.removeDefaultRouteBlackhole(device.id(), ipPrefix);
});
Set<IpPrefix> toAdd = Sets.difference(config.blackholeIPs(), prevConfig.blackholeIPs());
toAdd.forEach(ipPrefix -> {
srManager.routingRulePopulator.populateDefaultRouteBlackhole(device.id(), ipPrefix);
});
});
}
use of org.onosproject.segmentrouting.config.SegmentRoutingAppConfig in project trellis-control by opennetworkinglab.
the class BlackHoleCommand method doExecute.
@Override
protected void doExecute() {
SegmentRoutingService srService = AbstractShellCommand.get(SegmentRoutingService.class);
NetworkConfigService netcfgService = AbstractShellCommand.get(NetworkConfigService.class);
SegmentRoutingAppConfig appConfig = netcfgService.getConfig(srService.appId(), SegmentRoutingAppConfig.class);
if (appConfig == null) {
JsonNode jsonNode = new ObjectMapper().createObjectNode();
netcfgService.applyConfig(srService.appId(), SegmentRoutingAppConfig.class, jsonNode);
appConfig = netcfgService.getConfig(srService.appId(), SegmentRoutingAppConfig.class);
}
Set<IpPrefix> blackHoleIps;
switch(op) {
case "list":
appConfig.blackholeIPs().forEach(prefix -> print(prefix.toString()));
break;
case "add":
blackHoleIps = Sets.newConcurrentHashSet(appConfig.blackholeIPs());
blackHoleIps.add(IpPrefix.valueOf(prefix));
appConfig.setBalckholeIps(blackHoleIps);
appConfig.apply();
break;
case "remove":
blackHoleIps = Sets.newConcurrentHashSet(appConfig.blackholeIPs());
blackHoleIps.remove(IpPrefix.valueOf(prefix));
appConfig.setBalckholeIps(blackHoleIps);
appConfig.apply();
break;
default:
throw new UnsupportedOperationException("Unknown operation " + op);
}
}
Aggregations