[ONOS-4171] BGP topology port problem.
Change-Id: I603aa7eafd72b8104179234fafc4877fa0f0fdad
Showing
1 changed file
with
30 additions
and
9 deletions
| ... | @@ -20,9 +20,10 @@ import static org.onosproject.net.Device.Type.VIRTUAL; | ... | @@ -20,9 +20,10 @@ import static org.onosproject.net.Device.Type.VIRTUAL; |
| 20 | import static org.onosproject.incubator.net.resource.label.LabelResourceId.labelResourceId; | 20 | import static org.onosproject.incubator.net.resource.label.LabelResourceId.labelResourceId; |
| 21 | import static java.util.stream.Collectors.toList; | 21 | import static java.util.stream.Collectors.toList; |
| 22 | 22 | ||
| 23 | -import java.util.LinkedList; | 23 | +import java.util.ArrayList; |
| 24 | import java.util.List; | 24 | import java.util.List; |
| 25 | import java.util.Set; | 25 | import java.util.Set; |
| 26 | +import java.util.HashMap; | ||
| 26 | 27 | ||
| 27 | import org.onlab.packet.ChassisId; | 28 | import org.onlab.packet.ChassisId; |
| 28 | import org.onlab.packet.Ip4Address; | 29 | import org.onlab.packet.Ip4Address; |
| ... | @@ -160,6 +161,7 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi | ... | @@ -160,6 +161,7 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi |
| 160 | public static final int DELAY = 2; | 161 | public static final int DELAY = 2; |
| 161 | private LabelResourceId beginLabel = labelResourceId(5122); | 162 | private LabelResourceId beginLabel = labelResourceId(5122); |
| 162 | private LabelResourceId endLabel = labelResourceId(9217); | 163 | private LabelResourceId endLabel = labelResourceId(9217); |
| 164 | + private HashMap<DeviceId, List<PortDescription>> portMap = new HashMap<>(); | ||
| 163 | 165 | ||
| 164 | @Activate | 166 | @Activate |
| 165 | public void activate() { | 167 | public void activate() { |
| ... | @@ -286,14 +288,35 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi | ... | @@ -286,14 +288,35 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi |
| 286 | deviceProviderService.deviceDisconnected(deviceId); | 288 | deviceProviderService.deviceDisconnected(deviceId); |
| 287 | } | 289 | } |
| 288 | 290 | ||
| 291 | + private List<PortDescription> buildPortDescriptions(DeviceId deviceId, | ||
| 292 | + PortNumber portNumber) { | ||
| 293 | + | ||
| 294 | + List<PortDescription> portList; | ||
| 295 | + | ||
| 296 | + if (portMap.containsKey(deviceId)) { | ||
| 297 | + portList = portMap.get(deviceId); | ||
| 298 | + } else { | ||
| 299 | + portList = new ArrayList<>(); | ||
| 300 | + } | ||
| 301 | + if (portNumber != null) { | ||
| 302 | + PortDescription portDescriptions = new DefaultPortDescription(portNumber, true); | ||
| 303 | + portList.add(portDescriptions); | ||
| 304 | + } | ||
| 305 | + | ||
| 306 | + portMap.put(deviceId, portList); | ||
| 307 | + return portList; | ||
| 308 | + } | ||
| 309 | + | ||
| 289 | @Override | 310 | @Override |
| 290 | public void addLink(BgpLinkLsNlriVer4 linkNlri, PathAttrNlriDetails details) throws BgpParseException { | 311 | public void addLink(BgpLinkLsNlriVer4 linkNlri, PathAttrNlriDetails details) throws BgpParseException { |
| 291 | log.debug("Addlink {}", linkNlri.toString()); | 312 | log.debug("Addlink {}", linkNlri.toString()); |
| 292 | 313 | ||
| 293 | - if (linkProviderService == null) { | 314 | + LinkDescription linkDes = buildLinkDes(linkNlri, details, true); |
| 315 | + | ||
| 316 | + //If already link exists, return | ||
| 317 | + if (linkService.getLink(linkDes.src(), linkDes.dst()) != null || linkProviderService == null) { | ||
| 294 | return; | 318 | return; |
| 295 | } | 319 | } |
| 296 | - LinkDescription linkDes = buildLinkDes(linkNlri, details, true); | ||
| 297 | 320 | ||
| 298 | /* | 321 | /* |
| 299 | * Update link ports and configure bandwidth on source and destination port using networkConfig service | 322 | * Update link ports and configure bandwidth on source and destination port using networkConfig service |
| ... | @@ -304,13 +327,11 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi | ... | @@ -304,13 +327,11 @@ public class BgpTopologyProvider extends AbstractProvider implements DeviceProvi |
| 304 | } | 327 | } |
| 305 | 328 | ||
| 306 | //Updating ports of the link | 329 | //Updating ports of the link |
| 307 | - List<PortDescription> srcPortDescriptions = new LinkedList<>(); | 330 | + deviceProviderService.updatePorts(linkDes.src().deviceId(), buildPortDescriptions(linkDes.src().deviceId(), |
| 308 | - srcPortDescriptions.add(new DefaultPortDescription(linkDes.src().port(), true)); | 331 | + linkDes.src().port())); |
| 309 | - deviceProviderService.updatePorts(linkDes.src().deviceId(), srcPortDescriptions); | ||
| 310 | 332 | ||
| 311 | - List<PortDescription> dstPortDescriptions = new LinkedList<>(); | 333 | + deviceProviderService.updatePorts(linkDes.dst().deviceId(), buildPortDescriptions(linkDes.dst().deviceId(), |
| 312 | - dstPortDescriptions.add(new DefaultPortDescription(linkDes.dst().port(), true)); | 334 | + linkDes.dst().port())); |
| 313 | - deviceProviderService.updatePorts(linkDes.dst().deviceId(), dstPortDescriptions); | ||
| 314 | 335 | ||
| 315 | linkProviderService.linkDetected(linkDes); | 336 | linkProviderService.linkDetected(linkDes); |
| 316 | } | 337 | } | ... | ... |
-
Please register or login to post a comment