sangho
Committed by Gerrit Code Review

ONOS-1521 : Supports Leaf-Spine topology (tested with 4 x 4 )

- Supports ECMPNotSupportedInTransitRouter option
- Adds Leaf-Spine config file
- Removes the temporary NetworkConfigHanlder class
- Removes the grouphandler dependency
- Removes the grouphandler app
Change-Id: I8c70e81bfb4062e251b25c0fa23ef2c92419a75c
...@@ -43,7 +43,7 @@ public class ArpHandler { ...@@ -43,7 +43,7 @@ public class ArpHandler {
43 private static Logger log = LoggerFactory.getLogger(ArpHandler.class); 43 private static Logger log = LoggerFactory.getLogger(ArpHandler.class);
44 44
45 private SegmentRoutingManager srManager; 45 private SegmentRoutingManager srManager;
46 - private NetworkConfigHandler config; 46 + private DeviceConfiguration config;
47 47
48 /** 48 /**
49 * Creates an ArpHandler object. 49 * Creates an ArpHandler object.
...@@ -52,7 +52,7 @@ public class ArpHandler { ...@@ -52,7 +52,7 @@ public class ArpHandler {
52 */ 52 */
53 public ArpHandler(SegmentRoutingManager srManager) { 53 public ArpHandler(SegmentRoutingManager srManager) {
54 this.srManager = srManager; 54 this.srManager = srManager;
55 - this.config = checkNotNull(srManager.networkConfigHandler); 55 + this.config = checkNotNull(srManager.deviceConfiguration);
56 } 56 }
57 57
58 /** 58 /**
...@@ -96,8 +96,8 @@ public class ArpHandler { ...@@ -96,8 +96,8 @@ public class ArpHandler {
96 // ARP request for router 96 // ARP request for router
97 if (isArpReqForRouter(deviceId, arpRequest)) { 97 if (isArpReqForRouter(deviceId, arpRequest)) {
98 Ip4Address targetAddress = Ip4Address.valueOf(arpRequest.getTargetProtocolAddress()); 98 Ip4Address targetAddress = Ip4Address.valueOf(arpRequest.getTargetProtocolAddress());
99 - sendArpResponse(arpRequest, config.getRouterMac(targetAddress));
100 99
100 + sendArpResponse(arpRequest, config.getRouterMacForAGatewayIp(targetAddress));
101 // ARP request for known hosts 101 // ARP request for known hosts
102 } else if (srManager.hostService.getHost(targetHostId) != null) { 102 } else if (srManager.hostService.getHost(targetHostId) != null) {
103 MacAddress targetMac = srManager.hostService.getHost(targetHostId).mac(); 103 MacAddress targetMac = srManager.hostService.getHost(targetHostId).mac();
...@@ -111,7 +111,7 @@ public class ArpHandler { ...@@ -111,7 +111,7 @@ public class ArpHandler {
111 111
112 112
113 private boolean isArpReqForRouter(DeviceId deviceId, ARP arpRequest) { 113 private boolean isArpReqForRouter(DeviceId deviceId, ARP arpRequest) {
114 - List<Ip4Address> gatewayIpAddresses = config.getGatewayIpAddress(deviceId); 114 + List<Ip4Address> gatewayIpAddresses = config.getSubnetGatewayIps(deviceId);
115 if (gatewayIpAddresses != null) { 115 if (gatewayIpAddresses != null) {
116 Ip4Address targetProtocolAddress = Ip4Address.valueOf(arpRequest 116 Ip4Address targetProtocolAddress = Ip4Address.valueOf(arpRequest
117 .getTargetProtocolAddress()); 117 .getTargetProtocolAddress());
...@@ -123,7 +123,7 @@ public class ArpHandler { ...@@ -123,7 +123,7 @@ public class ArpHandler {
123 } 123 }
124 124
125 private boolean isArpReqForSubnet(DeviceId deviceId, ARP arpRequest) { 125 private boolean isArpReqForSubnet(DeviceId deviceId, ARP arpRequest) {
126 - return config.getSubnetInfo(deviceId).stream() 126 + return config.getSubnets(deviceId).stream()
127 .anyMatch((prefix)-> 127 .anyMatch((prefix)->
128 prefix.contains(Ip4Address. 128 prefix.contains(Ip4Address.
129 valueOf(arpRequest. 129 valueOf(arpRequest.
...@@ -139,9 +139,8 @@ public class ArpHandler { ...@@ -139,9 +139,8 @@ public class ArpHandler {
139 */ 139 */
140 public void sendArpRequest(DeviceId deviceId, IpAddress targetAddress, ConnectPoint inPort) { 140 public void sendArpRequest(DeviceId deviceId, IpAddress targetAddress, ConnectPoint inPort) {
141 141
142 - byte[] senderMacAddress = config.getRouterMacAddress(deviceId).toBytes(); 142 + byte[] senderMacAddress = config.getDeviceMac(deviceId).toBytes();
143 - byte[] senderIpAddress = config.getRouterIpAddress(deviceId) 143 + byte[] senderIpAddress = config.getRouterIp(deviceId).toOctets();
144 - .getIp4Prefix().address().toOctets();
145 144
146 ARP arpRequest = new ARP(); 145 ARP arpRequest = new ARP();
147 arpRequest.setHardwareType(ARP.HW_TYPE_ETHERNET) 146 arpRequest.setHardwareType(ARP.HW_TYPE_ETHERNET)
......
...@@ -17,6 +17,7 @@ package org.onosproject.segmentrouting; ...@@ -17,6 +17,7 @@ package org.onosproject.segmentrouting;
17 17
18 import com.google.common.collect.Maps; 18 import com.google.common.collect.Maps;
19 import com.google.common.collect.Sets; 19 import com.google.common.collect.Sets;
20 +import org.onlab.packet.Ip4Address;
20 import org.onlab.packet.Ip4Prefix; 21 import org.onlab.packet.Ip4Prefix;
21 import org.onlab.packet.IpPrefix; 22 import org.onlab.packet.IpPrefix;
22 import org.onosproject.net.Device; 23 import org.onosproject.net.Device;
...@@ -41,8 +42,8 @@ public class DefaultRoutingHandler { ...@@ -41,8 +42,8 @@ public class DefaultRoutingHandler {
41 42
42 private SegmentRoutingManager srManager; 43 private SegmentRoutingManager srManager;
43 private RoutingRulePopulator rulePopulator; 44 private RoutingRulePopulator rulePopulator;
44 - private NetworkConfigHandler config;
45 private HashMap<DeviceId, ECMPShortestPathGraph> currentEcmpSpgMap; 45 private HashMap<DeviceId, ECMPShortestPathGraph> currentEcmpSpgMap;
46 + private DeviceConfiguration config;
46 private Status populationStatus; 47 private Status populationStatus;
47 48
48 /** 49 /**
...@@ -70,7 +71,7 @@ public class DefaultRoutingHandler { ...@@ -70,7 +71,7 @@ public class DefaultRoutingHandler {
70 public DefaultRoutingHandler(SegmentRoutingManager srManager) { 71 public DefaultRoutingHandler(SegmentRoutingManager srManager) {
71 this.srManager = srManager; 72 this.srManager = srManager;
72 this.rulePopulator = checkNotNull(srManager.routingRulePopulator); 73 this.rulePopulator = checkNotNull(srManager.routingRulePopulator);
73 - this.config = checkNotNull(srManager.networkConfigHandler); 74 + this.config = checkNotNull(srManager.deviceConfiguration);
74 this.populationStatus = Status.IDLE; 75 this.populationStatus = Status.IDLE;
75 this.currentEcmpSpgMap = Maps.newHashMap(); 76 this.currentEcmpSpgMap = Maps.newHashMap();
76 } 77 }
...@@ -356,8 +357,8 @@ public class DefaultRoutingHandler { ...@@ -356,8 +357,8 @@ public class DefaultRoutingHandler {
356 357
357 // If both target switch and dest switch are edge routers, then set IP rule 358 // If both target switch and dest switch are edge routers, then set IP rule
358 // for both subnet and router IP. 359 // for both subnet and router IP.
359 - if (config.isEdgeRouter(targetSw) && config.isEdgeRouter(destSw)) { 360 + if (config.isEdgeDevice(targetSw) && config.isEdgeDevice(destSw)) {
360 - List<Ip4Prefix> subnets = config.getSubnetInfo(destSw); 361 + List<Ip4Prefix> subnets = config.getSubnets(destSw);
361 result = rulePopulator.populateIpRuleForSubnet(targetSw, 362 result = rulePopulator.populateIpRuleForSubnet(targetSw,
362 subnets, 363 subnets,
363 destSw, 364 destSw,
...@@ -366,29 +367,28 @@ public class DefaultRoutingHandler { ...@@ -366,29 +367,28 @@ public class DefaultRoutingHandler {
366 return false; 367 return false;
367 } 368 }
368 369
369 - IpPrefix routerIp = config.getRouterIpAddress(destSw); 370 + Ip4Address routerIp = config.getRouterIp(destSw);
370 - result = rulePopulator.populateIpRuleForRouter(targetSw, routerIp, destSw, nextHops); 371 + IpPrefix routerIpPrefix = IpPrefix.valueOf(routerIp, IpPrefix.MAX_INET_MASK_LENGTH);
372 + result = rulePopulator.populateIpRuleForRouter(targetSw, routerIpPrefix, destSw, nextHops);
371 if (!result) { 373 if (!result) {
372 return false; 374 return false;
373 } 375 }
374 376
375 // If the target switch is an edge router, then set IP rules for the router IP. 377 // If the target switch is an edge router, then set IP rules for the router IP.
376 - } else if (config.isEdgeRouter(targetSw)) { 378 + } else if (config.isEdgeDevice(targetSw)) {
377 - IpPrefix routerIp = config.getRouterIpAddress(destSw); 379 + Ip4Address routerIp = config.getRouterIp(destSw);
378 - result = rulePopulator.populateIpRuleForRouter(targetSw, routerIp, destSw, nextHops); 380 + IpPrefix routerIpPrefix = IpPrefix.valueOf(routerIp, IpPrefix.MAX_INET_MASK_LENGTH);
381 + result = rulePopulator.populateIpRuleForRouter(targetSw, routerIpPrefix, destSw, nextHops);
379 if (!result) { 382 if (!result) {
380 return false; 383 return false;
381 } 384 }
382 385
383 // If the target switch is an transit router, then set MPLS rules only. 386 // If the target switch is an transit router, then set MPLS rules only.
384 - } else if (config.isTransitRouter(targetSw)) { 387 + } else if (!config.isEdgeDevice(targetSw)) {
385 result = rulePopulator.populateMplsRule(targetSw, destSw, nextHops); 388 result = rulePopulator.populateMplsRule(targetSw, destSw, nextHops);
386 if (!result) { 389 if (!result) {
387 return false; 390 return false;
388 } 391 }
389 - } else {
390 - log.warn("The switch {} is neither an edge router nor a transit router.", targetSw);
391 - return false;
392 } 392 }
393 393
394 return true; 394 return true;
......
...@@ -313,4 +313,31 @@ public class DeviceConfiguration implements DeviceProperties { ...@@ -313,4 +313,31 @@ public class DeviceConfiguration implements DeviceProperties {
313 log.debug("Cannot find a router for {}", gatewayIpAddress); 313 log.debug("Cannot find a router for {}", gatewayIpAddress);
314 return null; 314 return null;
315 } 315 }
316 +
317 +
318 + /**
319 + * Checks if the host is in the subnet defined in the router with the
320 + * device ID given.
321 + *
322 + * @param deviceId device identification of the router
323 + * @param hostIp host IP address to check
324 + * @return true if the host is within the subnet of the router,
325 + * false if no subnet is defined under the router or if the host is not
326 + * within the subnet defined in the router
327 + */
328 + public boolean inSameSubnet(DeviceId deviceId, Ip4Address hostIp) {
329 +
330 + List<Ip4Prefix> subnets = getSubnets(deviceId);
331 + if (subnets == null) {
332 + return false;
333 + }
334 +
335 + for (Ip4Prefix subnet: subnets) {
336 + if (subnet.contains(hostIp)) {
337 + return true;
338 + }
339 + }
340 +
341 + return false;
342 + }
316 } 343 }
......
...@@ -39,7 +39,7 @@ public class IcmpHandler { ...@@ -39,7 +39,7 @@ public class IcmpHandler {
39 39
40 private static Logger log = LoggerFactory.getLogger(IcmpHandler.class); 40 private static Logger log = LoggerFactory.getLogger(IcmpHandler.class);
41 private SegmentRoutingManager srManager; 41 private SegmentRoutingManager srManager;
42 - private NetworkConfigHandler config; 42 + private DeviceConfiguration config;
43 43
44 /** 44 /**
45 * Creates an IcmpHandler object. 45 * Creates an IcmpHandler object.
...@@ -48,7 +48,7 @@ public class IcmpHandler { ...@@ -48,7 +48,7 @@ public class IcmpHandler {
48 */ 48 */
49 public IcmpHandler(SegmentRoutingManager srManager) { 49 public IcmpHandler(SegmentRoutingManager srManager) {
50 this.srManager = srManager; 50 this.srManager = srManager;
51 - this.config = checkNotNull(srManager.networkConfigHandler); 51 + this.config = checkNotNull(srManager.deviceConfiguration);
52 } 52 }
53 53
54 /** 54 /**
...@@ -69,8 +69,9 @@ public class IcmpHandler { ...@@ -69,8 +69,9 @@ public class IcmpHandler {
69 DeviceId deviceId = connectPoint.deviceId(); 69 DeviceId deviceId = connectPoint.deviceId();
70 Ip4Address destinationAddress = 70 Ip4Address destinationAddress =
71 Ip4Address.valueOf(ipv4.getDestinationAddress()); 71 Ip4Address.valueOf(ipv4.getDestinationAddress());
72 - List<Ip4Address> gatewayIpAddresses = config.getGatewayIpAddress(deviceId); 72 + List<Ip4Address> gatewayIpAddresses = config.getSubnetGatewayIps(deviceId);
73 - IpPrefix routerIpPrefix = config.getRouterIpAddress(deviceId); 73 + Ip4Address routerIp = config.getRouterIp(deviceId);
74 + IpPrefix routerIpPrefix = IpPrefix.valueOf(routerIp, IpPrefix.MAX_INET_MASK_LENGTH);
74 Ip4Address routerIpAddress = routerIpPrefix.getIp4Prefix().address(); 75 Ip4Address routerIpAddress = routerIpPrefix.getIp4Prefix().address();
75 76
76 // ICMP to the router IP or gateway IP 77 // ICMP to the router IP or gateway IP
...@@ -122,8 +123,8 @@ public class IcmpHandler { ...@@ -122,8 +123,8 @@ public class IcmpHandler {
122 icmpReplyEth.setVlanID(icmpRequest.getVlanID()); 123 icmpReplyEth.setVlanID(icmpRequest.getVlanID());
123 124
124 Ip4Address destIpAddress = Ip4Address.valueOf(icmpReplyIpv4.getDestinationAddress()); 125 Ip4Address destIpAddress = Ip4Address.valueOf(icmpReplyIpv4.getDestinationAddress());
125 - Ip4Address destRouterAddress = config.getDestinationRouterAddress(destIpAddress); 126 + Ip4Address destRouterAddress = config.getRouterIpAddressForASubnetHost(destIpAddress);
126 - int sid = config.getMplsId(destRouterAddress); 127 + int sid = config.getSegmentId(destRouterAddress);
127 if (sid < 0) { 128 if (sid < 0) {
128 log.warn("Cannot find the Segment ID for {}", destAddress); 129 log.warn("Cannot find the Segment ID for {}", destAddress);
129 return; 130 return;
...@@ -138,7 +139,7 @@ public class IcmpHandler { ...@@ -138,7 +139,7 @@ public class IcmpHandler {
138 IPv4 ipPacket = (IPv4) payload.getPayload(); 139 IPv4 ipPacket = (IPv4) payload.getPayload();
139 Ip4Address destIpAddress = Ip4Address.valueOf(ipPacket.getDestinationAddress()); 140 Ip4Address destIpAddress = Ip4Address.valueOf(ipPacket.getDestinationAddress());
140 141
141 - if (sid == -1 || config.getMplsId(payload.getDestinationMAC()) == sid || 142 + if (sid == -1 || config.getSegmentId(payload.getDestinationMAC()) == sid ||
142 config.inSameSubnet(outport.deviceId(), destIpAddress)) { 143 config.inSameSubnet(outport.deviceId(), destIpAddress)) {
143 TrafficTreatment treatment = DefaultTrafficTreatment.builder(). 144 TrafficTreatment treatment = DefaultTrafficTreatment.builder().
144 setOutput(outport.port()).build(); 145 setOutput(outport.port()).build();
...@@ -164,4 +165,6 @@ public class IcmpHandler { ...@@ -164,4 +165,6 @@ public class IcmpHandler {
164 srManager.packetService.emit(packet); 165 srManager.packetService.emit(packet);
165 } 166 }
166 } 167 }
168 +
169 +
167 } 170 }
......
...@@ -39,7 +39,7 @@ public class IpHandler { ...@@ -39,7 +39,7 @@ public class IpHandler {
39 39
40 private static Logger log = LoggerFactory.getLogger(IpHandler.class); 40 private static Logger log = LoggerFactory.getLogger(IpHandler.class);
41 private SegmentRoutingManager srManager; 41 private SegmentRoutingManager srManager;
42 - private NetworkConfigHandler config; 42 + private DeviceConfiguration config;
43 private ConcurrentHashMap<Ip4Address, ConcurrentLinkedQueue<IPv4>> ipPacketQueue; 43 private ConcurrentHashMap<Ip4Address, ConcurrentLinkedQueue<IPv4>> ipPacketQueue;
44 44
45 /** 45 /**
...@@ -49,7 +49,7 @@ public class IpHandler { ...@@ -49,7 +49,7 @@ public class IpHandler {
49 */ 49 */
50 public IpHandler(SegmentRoutingManager srManager) { 50 public IpHandler(SegmentRoutingManager srManager) {
51 this.srManager = srManager; 51 this.srManager = srManager;
52 - this.config = checkNotNull(srManager.networkConfigHandler); 52 + this.config = checkNotNull(srManager.deviceConfiguration);
53 ipPacketQueue = new ConcurrentHashMap<Ip4Address, ConcurrentLinkedQueue<IPv4>>(); 53 ipPacketQueue = new ConcurrentHashMap<Ip4Address, ConcurrentLinkedQueue<IPv4>>();
54 } 54 }
55 55
...@@ -129,8 +129,7 @@ public class IpHandler { ...@@ -129,8 +129,7 @@ public class IpHandler {
129 for (Host dest: srManager.hostService.getHostsByIp(destIpAddress)) { 129 for (Host dest: srManager.hostService.getHostsByIp(destIpAddress)) {
130 Ethernet eth = new Ethernet(); 130 Ethernet eth = new Ethernet();
131 eth.setDestinationMACAddress(dest.mac()); 131 eth.setDestinationMACAddress(dest.mac());
132 - eth.setSourceMACAddress(config.getRouterMacAddress( 132 + eth.setSourceMACAddress(config.getDeviceMac(deviceId));
133 - deviceId));
134 eth.setEtherType(Ethernet.TYPE_IPV4); 133 eth.setEtherType(Ethernet.TYPE_IPV4);
135 eth.setPayload(ipPacket); 134 eth.setPayload(ipPacket);
136 135
...@@ -141,7 +140,9 @@ public class IpHandler { ...@@ -141,7 +140,9 @@ public class IpHandler {
141 srManager.packetService.emit(packet); 140 srManager.packetService.emit(packet);
142 ipPacketQueue.get(destIpAddress).remove(ipPacket); 141 ipPacketQueue.get(destIpAddress).remove(ipPacket);
143 } 142 }
143 + ipPacketQueue.get(destIpAddress).remove(ipPacket);
144 } 144 }
145 } 145 }
146 } 146 }
147 +
147 } 148 }
......
1 -/*
2 - * Copyright 2015 Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.segmentrouting;
17 -
18 -import com.google.common.collect.Lists;
19 -
20 -import org.onlab.packet.Ip4Address;
21 -import org.onlab.packet.Ip4Prefix;
22 -import org.onlab.packet.IpPrefix;
23 -import org.onlab.packet.MacAddress;
24 -import org.onosproject.net.DeviceId;
25 -import org.onosproject.net.Link;
26 -import org.onosproject.net.PortNumber;
27 -import org.slf4j.Logger;
28 -import org.slf4j.LoggerFactory;
29 -
30 -import java.util.List;
31 -import java.util.Set;
32 -
33 -/**
34 - * This class is temporary class and used only for test.
35 - * It will be replaced with "real" Network Config Manager.
36 - *
37 - * TODO: Knock off this wrapper and directly use DeviceConfiguration class
38 - */
39 -
40 -public class NetworkConfigHandler {
41 -
42 - private static Logger log = LoggerFactory.getLogger(NetworkConfigHandler.class);
43 - private SegmentRoutingManager srManager;
44 - private DeviceConfiguration deviceConfig;
45 -
46 - public NetworkConfigHandler(SegmentRoutingManager srManager,
47 - DeviceConfiguration deviceConfig) {
48 - this.srManager = srManager;
49 - this.deviceConfig = deviceConfig;
50 - }
51 -
52 - public List<Ip4Address> getGatewayIpAddress(DeviceId deviceId) {
53 - return this.deviceConfig.getSubnetGatewayIps(deviceId);
54 - }
55 -
56 - public IpPrefix getRouterIpAddress(DeviceId deviceId) {
57 - return IpPrefix.valueOf(deviceConfig.getRouterIp(deviceId), 32);
58 - }
59 -
60 - public MacAddress getRouterMacAddress(DeviceId deviceId) {
61 - return deviceConfig.getDeviceMac(deviceId);
62 - }
63 -
64 - public boolean inSameSubnet(DeviceId deviceId, Ip4Address destIp) {
65 -
66 - List<Ip4Prefix> subnets = getSubnetInfo(deviceId);
67 - if (subnets == null) {
68 - return false;
69 - }
70 -
71 - return subnets.stream()
72 - .anyMatch((subnet) -> subnet.contains(destIp));
73 - }
74 -
75 - public boolean inSameSubnet(Ip4Address address, int sid) {
76 - DeviceId deviceId = deviceConfig.getDeviceId(sid);
77 - if (deviceId == null) {
78 - log.warn("Cannot find a device for SID {}", sid);
79 - return false;
80 - }
81 -
82 - return inSameSubnet(deviceId, address);
83 - }
84 -
85 - public List<Ip4Prefix> getSubnetInfo(DeviceId deviceId) {
86 - return deviceConfig.getSubnets(deviceId);
87 - }
88 -
89 - public int getMplsId(DeviceId deviceId) {
90 - return deviceConfig.getSegmentId(deviceId);
91 - }
92 -
93 - public int getMplsId(MacAddress routerMac) {
94 - return deviceConfig.getSegmentId(routerMac);
95 - }
96 -
97 - public int getMplsId(Ip4Address routerIpAddress) {
98 - return deviceConfig.getSegmentId(routerIpAddress);
99 - }
100 -
101 - public boolean isEcmpNotSupportedInTransit(DeviceId deviceId) {
102 - return false;
103 - }
104 -
105 - public boolean isTransitRouter(DeviceId deviceId) {
106 - return !(deviceConfig.isEdgeDevice(deviceId));
107 - }
108 -
109 -
110 - public boolean isEdgeRouter(DeviceId deviceId) {
111 - return deviceConfig.isEdgeDevice(deviceId);
112 - }
113 -
114 - private List<PortNumber> getPortsToNeighbors(DeviceId deviceId, List<DeviceId> fwdSws) {
115 -
116 - List<PortNumber> portNumbers = Lists.newArrayList();
117 -
118 - Set<Link> links = srManager.linkService.getDeviceEgressLinks(deviceId);
119 - for (Link link: links) {
120 - for (DeviceId swId: fwdSws) {
121 - if (link.dst().deviceId().equals(swId)) {
122 - portNumbers.add(link.src().port());
123 - break;
124 - }
125 - }
126 - }
127 -
128 - return portNumbers;
129 - }
130 -
131 - public List<PortNumber> getPortsToDevice(DeviceId deviceId) {
132 - List<PortNumber> portNumbers = Lists.newArrayList();
133 -
134 - Set<Link> links = srManager.linkService.getDeviceEgressLinks(deviceId);
135 - for (Link link: links) {
136 - if (link.dst().deviceId().equals(deviceId)) {
137 - portNumbers.add(link.src().port());
138 - }
139 - }
140 -
141 - return portNumbers;
142 - }
143 -
144 -
145 - public Ip4Address getDestinationRouterAddress(Ip4Address destIpAddress) {
146 - return deviceConfig.getRouterIpAddressForASubnetHost(destIpAddress);
147 - }
148 -
149 - public DeviceId getDeviceId(Ip4Address ip4Address) {
150 - return deviceConfig.getDeviceId(ip4Address);
151 - }
152 -
153 - public MacAddress getRouterMac(Ip4Address targetAddress) {
154 - return deviceConfig.getRouterMacForAGatewayIp(targetAddress);
155 - }
156 -}
...@@ -48,10 +48,9 @@ public class RoutingRulePopulator { ...@@ -48,10 +48,9 @@ public class RoutingRulePopulator {
48 48
49 private static final Logger log = LoggerFactory.getLogger(RoutingRulePopulator.class); 49 private static final Logger log = LoggerFactory.getLogger(RoutingRulePopulator.class);
50 50
51 - private final SegmentRoutingManager srManager;
52 - private final NetworkConfigHandler config;
53 private AtomicLong rulePopulationCounter; 51 private AtomicLong rulePopulationCounter;
54 - 52 + private SegmentRoutingManager srManager;
53 + private DeviceConfiguration config;
55 /** 54 /**
56 * Creates a RoutingRulePopulator object. 55 * Creates a RoutingRulePopulator object.
57 * 56 *
...@@ -59,7 +58,7 @@ public class RoutingRulePopulator { ...@@ -59,7 +58,7 @@ public class RoutingRulePopulator {
59 */ 58 */
60 public RoutingRulePopulator(SegmentRoutingManager srManager) { 59 public RoutingRulePopulator(SegmentRoutingManager srManager) {
61 this.srManager = srManager; 60 this.srManager = srManager;
62 - this.config = checkNotNull(srManager.networkConfigHandler); 61 + this.config = checkNotNull(srManager.deviceConfiguration);
63 this.rulePopulationCounter = new AtomicLong(0); 62 this.rulePopulationCounter = new AtomicLong(0);
64 } 63 }
65 64
...@@ -94,7 +93,7 @@ public class RoutingRulePopulator { ...@@ -94,7 +93,7 @@ public class RoutingRulePopulator {
94 sbuilder.matchEthType(Ethernet.TYPE_IPV4); 93 sbuilder.matchEthType(Ethernet.TYPE_IPV4);
95 94
96 tbuilder.setEthDst(hostMac) 95 tbuilder.setEthDst(hostMac)
97 - .setEthSrc(config.getRouterMacAddress(deviceId)) 96 + .setEthSrc(config.getDeviceMac(deviceId))
98 .setOutput(outPort); 97 .setOutput(outPort);
99 98
100 TrafficTreatment treatment = tbuilder.build(); 99 TrafficTreatment treatment = tbuilder.build();
...@@ -156,7 +155,7 @@ public class RoutingRulePopulator { ...@@ -156,7 +155,7 @@ public class RoutingRulePopulator {
156 ns = new NeighborSet(nextHops); 155 ns = new NeighborSet(nextHops);
157 } else { 156 } else {
158 tbuilder.copyTtlOut(); 157 tbuilder.copyTtlOut();
159 - ns = new NeighborSet(nextHops, config.getMplsId(destSw)); 158 + ns = new NeighborSet(nextHops, config.getSegmentId(destSw));
160 } 159 }
161 160
162 DefaultGroupKey groupKey = (DefaultGroupKey) srManager.getGroupKey(ns); 161 DefaultGroupKey groupKey = (DefaultGroupKey) srManager.getGroupKey(ns);
...@@ -201,7 +200,7 @@ public class RoutingRulePopulator { ...@@ -201,7 +200,7 @@ public class RoutingRulePopulator {
201 Collection<TrafficTreatment> treatments = new ArrayList<>(); 200 Collection<TrafficTreatment> treatments = new ArrayList<>();
202 201
203 // TODO Handle the case of Bos == false 202 // TODO Handle the case of Bos == false
204 - sbuilder.matchMplsLabel(MplsLabel.mplsLabel(config.getMplsId(destSwId))); 203 + sbuilder.matchMplsLabel(MplsLabel.mplsLabel(config.getSegmentId(destSwId)));
205 sbuilder.matchEthType(Ethernet.MPLS_UNICAST); 204 sbuilder.matchEthType(Ethernet.MPLS_UNICAST);
206 205
207 //If the next hop is the destination router, do PHP 206 //If the next hop is the destination router, do PHP
...@@ -262,15 +261,15 @@ public class RoutingRulePopulator { ...@@ -262,15 +261,15 @@ public class RoutingRulePopulator {
262 tbuilder.decMplsTtl(); 261 tbuilder.decMplsTtl();
263 } 262 }
264 263
265 - if (config.isEcmpNotSupportedInTransit(deviceId) 264 + if (!isECMPSupportedInTransitRouter() && !config.isEdgeDevice(deviceId)) {
266 - && config.isTransitRouter(deviceId)) {
267 Link link = selectOneLink(deviceId, nextHops); 265 Link link = selectOneLink(deviceId, nextHops);
266 + DeviceId nextHop = (DeviceId) nextHops.toArray()[0];
268 if (link == null) { 267 if (link == null) {
269 log.warn("No link from {} to {}", deviceId, nextHops); 268 log.warn("No link from {} to {}", deviceId, nextHops);
270 return null; 269 return null;
271 } 270 }
272 - tbuilder.setEthSrc(config.getRouterMacAddress(deviceId)) 271 + tbuilder.setEthSrc(config.getDeviceMac(deviceId))
273 - .setEthDst(config.getRouterMacAddress(link.dst().deviceId())) 272 + .setEthDst(config.getDeviceMac(nextHop))
274 .setOutput(link.src().port()); 273 .setOutput(link.src().port());
275 } else { 274 } else {
276 NeighborSet ns = new NeighborSet(nextHops); 275 NeighborSet ns = new NeighborSet(nextHops);
...@@ -292,6 +291,12 @@ public class RoutingRulePopulator { ...@@ -292,6 +291,12 @@ public class RoutingRulePopulator {
292 return tbuilder.build(); 291 return tbuilder.build();
293 } 292 }
294 293
294 + private boolean isECMPSupportedInTransitRouter() {
295 +
296 + // TODO: remove this function when objectives subsystem is supported.
297 + return false;
298 + }
299 +
295 /** 300 /**
296 * Populates VLAN flows rules. 301 * Populates VLAN flows rules.
297 * All packets are forwarded to TMAC table. 302 * All packets are forwarded to TMAC table.
...@@ -327,7 +332,7 @@ public class RoutingRulePopulator { ...@@ -327,7 +332,7 @@ public class RoutingRulePopulator {
327 // flow rule for IP packets 332 // flow rule for IP packets
328 TrafficSelector selectorIp = DefaultTrafficSelector.builder() 333 TrafficSelector selectorIp = DefaultTrafficSelector.builder()
329 .matchEthType(Ethernet.TYPE_IPV4) 334 .matchEthType(Ethernet.TYPE_IPV4)
330 - .matchEthDst(config.getRouterMacAddress(deviceId)) 335 + .matchEthDst(config.getDeviceMac(deviceId))
331 .build(); 336 .build();
332 TrafficTreatment treatmentIp = DefaultTrafficTreatment.builder() 337 TrafficTreatment treatmentIp = DefaultTrafficTreatment.builder()
333 .transition(FlowRule.Type.IP) 338 .transition(FlowRule.Type.IP)
...@@ -341,7 +346,7 @@ public class RoutingRulePopulator { ...@@ -341,7 +346,7 @@ public class RoutingRulePopulator {
341 // flow rule for MPLS packets 346 // flow rule for MPLS packets
342 TrafficSelector selectorMpls = DefaultTrafficSelector.builder() 347 TrafficSelector selectorMpls = DefaultTrafficSelector.builder()
343 .matchEthType(Ethernet.MPLS_UNICAST) 348 .matchEthType(Ethernet.MPLS_UNICAST)
344 - .matchEthDst(config.getRouterMacAddress(deviceId)) 349 + .matchEthDst(config.getDeviceMac(deviceId))
345 .build(); 350 .build();
346 TrafficTreatment treatmentMpls = DefaultTrafficTreatment.builder() 351 TrafficTreatment treatmentMpls = DefaultTrafficTreatment.builder()
347 .transition(FlowRule.Type.MPLS) 352 .transition(FlowRule.Type.MPLS)
......
...@@ -99,15 +99,14 @@ public class SegmentRoutingManager { ...@@ -99,15 +99,14 @@ public class SegmentRoutingManager {
99 99
100 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 100 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
101 protected MastershipService mastershipService; 101 protected MastershipService mastershipService;
102 - protected NetworkConfigHandler networkConfigHandler = null;
103 protected ArpHandler arpHandler = null; 102 protected ArpHandler arpHandler = null;
104 protected IcmpHandler icmpHandler = null; 103 protected IcmpHandler icmpHandler = null;
105 protected IpHandler ipHandler = null; 104 protected IpHandler ipHandler = null;
106 protected RoutingRulePopulator routingRulePopulator = null; 105 protected RoutingRulePopulator routingRulePopulator = null;
107 protected ApplicationId appId; 106 protected ApplicationId appId;
107 + protected DeviceConfiguration deviceConfiguration = null;
108 108
109 private DefaultRoutingHandler defaultRoutingHandler = null; 109 private DefaultRoutingHandler defaultRoutingHandler = null;
110 - private DeviceConfiguration deviceConfiguration = null;
111 private InternalPacketProcessor processor = new InternalPacketProcessor(); 110 private InternalPacketProcessor processor = new InternalPacketProcessor();
112 private InternalEventHandler eventHandler = new InternalEventHandler(); 111 private InternalEventHandler eventHandler = new InternalEventHandler();
113 112
...@@ -129,8 +128,6 @@ public class SegmentRoutingManager { ...@@ -129,8 +128,6 @@ public class SegmentRoutingManager {
129 appId = coreService.registerApplication("org.onosproject.segmentrouting"); 128 appId = coreService.registerApplication("org.onosproject.segmentrouting");
130 networkConfigService.init(); 129 networkConfigService.init();
131 deviceConfiguration = new DeviceConfiguration(networkConfigService); 130 deviceConfiguration = new DeviceConfiguration(networkConfigService);
132 - networkConfigHandler = new NetworkConfigHandler(this,
133 - deviceConfiguration);
134 arpHandler = new ArpHandler(this); 131 arpHandler = new ArpHandler(this);
135 icmpHandler = new IcmpHandler(this); 132 icmpHandler = new IcmpHandler(this);
136 ipHandler = new IpHandler(this); 133 ipHandler = new IpHandler(this);
...@@ -150,8 +147,8 @@ public class SegmentRoutingManager { ...@@ -150,8 +147,8 @@ public class SegmentRoutingManager {
150 appId, deviceConfiguration, linkService, groupService); 147 appId, deviceConfiguration, linkService, groupService);
151 groupHandler.createGroups(); 148 groupHandler.createGroups();
152 groupHandlerMap.put(device.id(), groupHandler); 149 groupHandlerMap.put(device.id(), groupHandler);
153 - log.debug("Initiating default group handling for {}", device.id());
154 defaultRoutingHandler.populateTtpRules(device.id()); 150 defaultRoutingHandler.populateTtpRules(device.id());
151 + log.debug("Initiating default group handling for {}", device.id());
155 } else { 152 } else {
156 log.debug("Activate: Local role {} " 153 log.debug("Activate: Local role {} "
157 + "is not MASTER for device {}", 154 + "is not MASTER for device {}",
...@@ -162,7 +159,6 @@ public class SegmentRoutingManager { ...@@ -162,7 +159,6 @@ public class SegmentRoutingManager {
162 } 159 }
163 160
164 defaultRoutingHandler.startPopulationProcess(); 161 defaultRoutingHandler.startPopulationProcess();
165 -
166 log.info("Started"); 162 log.info("Started");
167 } 163 }
168 164
......