Committed by
ShashikanthVH-Huawei
BGP flow spec RIBin.
Change-Id: I4909bb6e579311a74e25cb44172a2a010faa4e85
Showing
9 changed files
with
159 additions
and
43 deletions
| ... | @@ -124,6 +124,14 @@ public interface BgpPeer { | ... | @@ -124,6 +124,14 @@ public interface BgpPeer { |
| 124 | void buildAdjRibIn(List<BgpValueType> pathAttr) throws BgpParseException; | 124 | void buildAdjRibIn(List<BgpValueType> pathAttr) throws BgpParseException; |
| 125 | 125 | ||
| 126 | /** | 126 | /** |
| 127 | + * Update flow specification RIB for each peer. | ||
| 128 | + * | ||
| 129 | + * @param pathAttr list of Bgp path attributes | ||
| 130 | + * @throws BgpParseException while building flow spec RIB | ||
| 131 | + */ | ||
| 132 | + void buildFlowSpecRib(List<BgpValueType> pathAttr) throws BgpParseException; | ||
| 133 | + | ||
| 134 | + /** | ||
| 127 | * Return the BGP session info. | 135 | * Return the BGP session info. |
| 128 | * | 136 | * |
| 129 | * @return sessionInfo bgp session info | 137 | * @return sessionInfo bgp session info | ... | ... |
| ... | @@ -40,6 +40,14 @@ public class BgpFlowSpecDetails { | ... | @@ -40,6 +40,14 @@ public class BgpFlowSpecDetails { |
| 40 | } | 40 | } |
| 41 | 41 | ||
| 42 | /** | 42 | /** |
| 43 | + * Flow specification details object constructor. | ||
| 44 | + * | ||
| 45 | + */ | ||
| 46 | + public BgpFlowSpecDetails() { | ||
| 47 | + | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + /** | ||
| 43 | * Returns flow specification action tlv. | 51 | * Returns flow specification action tlv. |
| 44 | * | 52 | * |
| 45 | * @return flow specification action tlv | 53 | * @return flow specification action tlv |
| ... | @@ -84,6 +92,15 @@ public class BgpFlowSpecDetails { | ... | @@ -84,6 +92,15 @@ public class BgpFlowSpecDetails { |
| 84 | return this.flowSpecComponents; | 92 | return this.flowSpecComponents; |
| 85 | } | 93 | } |
| 86 | 94 | ||
| 95 | + /** | ||
| 96 | + * Sets flow specification components. | ||
| 97 | + * | ||
| 98 | + * @param flowSpecComponents flow specification components | ||
| 99 | + */ | ||
| 100 | + public void setFlowSpecComponents(List<BgpValueType> flowSpecComponents) { | ||
| 101 | + this.flowSpecComponents = flowSpecComponents; | ||
| 102 | + } | ||
| 103 | + | ||
| 87 | @Override | 104 | @Override |
| 88 | public int hashCode() { | 105 | public int hashCode() { |
| 89 | return Objects.hash(flowSpecComponents); | 106 | return Objects.hash(flowSpecComponents); | ... | ... |
| ... | @@ -41,6 +41,14 @@ public class BgpFlowSpecPrefix implements Comparable<Object> { | ... | @@ -41,6 +41,14 @@ public class BgpFlowSpecPrefix implements Comparable<Object> { |
| 41 | * @param sourcePrefix source prefix | 41 | * @param sourcePrefix source prefix |
| 42 | */ | 42 | */ |
| 43 | public BgpFlowSpecPrefix(IpPrefix destinationPrefix, IpPrefix sourcePrefix) { | 43 | public BgpFlowSpecPrefix(IpPrefix destinationPrefix, IpPrefix sourcePrefix) { |
| 44 | + if (destinationPrefix == null) { | ||
| 45 | + destinationPrefix = IpPrefix.valueOf(0, 0); | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + if (sourcePrefix == null) { | ||
| 49 | + sourcePrefix = IpPrefix.valueOf(0, 0); | ||
| 50 | + } | ||
| 51 | + | ||
| 44 | this.destinationPrefix = destinationPrefix; | 52 | this.destinationPrefix = destinationPrefix; |
| 45 | this.sourcePrefix = sourcePrefix; | 53 | this.sourcePrefix = sourcePrefix; |
| 46 | } | 54 | } | ... | ... |
| ... | @@ -189,7 +189,7 @@ public class MpReachNlri implements BgpValueType { | ... | @@ -189,7 +189,7 @@ public class MpReachNlri implements BgpValueType { |
| 189 | && ((safi == Constants.SAFI_FLOWSPEC_VALUE) | 189 | && ((safi == Constants.SAFI_FLOWSPEC_VALUE) |
| 190 | || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) { | 190 | || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) { |
| 191 | List<BgpValueType> flowSpecComponents = new LinkedList<>(); | 191 | List<BgpValueType> flowSpecComponents = new LinkedList<>(); |
| 192 | - | 192 | + RouteDistinguisher routeDistinguisher = null; |
| 193 | if (tempCb.readableBytes() > 0) { | 193 | if (tempCb.readableBytes() > 0) { |
| 194 | BgpValueType flowSpecComponent = null; | 194 | BgpValueType flowSpecComponent = null; |
| 195 | 195 | ||
| ... | @@ -203,6 +203,11 @@ public class MpReachNlri implements BgpValueType { | ... | @@ -203,6 +203,11 @@ public class MpReachNlri implements BgpValueType { |
| 203 | } | 203 | } |
| 204 | 204 | ||
| 205 | byte reserved = tempCb.readByte(); | 205 | byte reserved = tempCb.readByte(); |
| 206 | + | ||
| 207 | + if (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE) { | ||
| 208 | + routeDistinguisher = new RouteDistinguisher(); | ||
| 209 | + routeDistinguisher = RouteDistinguisher.read(tempCb); | ||
| 210 | + } | ||
| 206 | short totNlriLen = tempCb.getByte(tempCb.readerIndex()); | 211 | short totNlriLen = tempCb.getByte(tempCb.readerIndex()); |
| 207 | if (totNlriLen >= FLOW_SPEC_LEN) { | 212 | if (totNlriLen >= FLOW_SPEC_LEN) { |
| 208 | totNlriLen = tempCb.readShort(); | 213 | totNlriLen = tempCb.readShort(); |
| ... | @@ -260,7 +265,9 @@ public class MpReachNlri implements BgpValueType { | ... | @@ -260,7 +265,9 @@ public class MpReachNlri implements BgpValueType { |
| 260 | flowSpecComponents.add(flowSpecComponent); | 265 | flowSpecComponents.add(flowSpecComponent); |
| 261 | } | 266 | } |
| 262 | } | 267 | } |
| 263 | - return new MpReachNlri(new BgpFlowSpecDetails(flowSpecComponents), afi, safi); | 268 | + BgpFlowSpecDetails flowSpecDetails = new BgpFlowSpecDetails(flowSpecComponents); |
| 269 | + flowSpecDetails.setRouteDistinguiher(routeDistinguisher); | ||
| 270 | + return new MpReachNlri(flowSpecDetails, afi, safi); | ||
| 264 | } else { | 271 | } else { |
| 265 | throw new BgpParseException("Not Supporting afi " + afi + "safi " + safi); | 272 | throw new BgpParseException("Not Supporting afi " + afi + "safi " + safi); |
| 266 | } | 273 | } | ... | ... |
| ... | @@ -154,9 +154,14 @@ public class MpUnReachNlri implements BgpValueType { | ... | @@ -154,9 +154,14 @@ public class MpUnReachNlri implements BgpValueType { |
| 154 | && ((safi == Constants.SAFI_FLOWSPEC_VALUE) | 154 | && ((safi == Constants.SAFI_FLOWSPEC_VALUE) |
| 155 | || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) { | 155 | || (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE))) { |
| 156 | List<BgpValueType> flowSpecComponents = new LinkedList<>(); | 156 | List<BgpValueType> flowSpecComponents = new LinkedList<>(); |
| 157 | - | 157 | + RouteDistinguisher routeDistinguisher = null; |
| 158 | if (tempCb.readableBytes() > 0) { | 158 | if (tempCb.readableBytes() > 0) { |
| 159 | BgpValueType flowSpecComponent = null; | 159 | BgpValueType flowSpecComponent = null; |
| 160 | + | ||
| 161 | + if (safi == Constants.VPN_SAFI_FLOWSPEC_VALUE) { | ||
| 162 | + routeDistinguisher = new RouteDistinguisher(); | ||
| 163 | + routeDistinguisher = RouteDistinguisher.read(tempCb); | ||
| 164 | + } | ||
| 160 | short totNlriLen = tempCb.getByte(tempCb.readerIndex()); | 165 | short totNlriLen = tempCb.getByte(tempCb.readerIndex()); |
| 161 | if (totNlriLen >= FLOW_SPEC_LEN) { | 166 | if (totNlriLen >= FLOW_SPEC_LEN) { |
| 162 | totNlriLen = tempCb.readShort(); | 167 | totNlriLen = tempCb.readShort(); |
| ... | @@ -214,7 +219,9 @@ public class MpUnReachNlri implements BgpValueType { | ... | @@ -214,7 +219,9 @@ public class MpUnReachNlri implements BgpValueType { |
| 214 | flowSpecComponents.add(flowSpecComponent); | 219 | flowSpecComponents.add(flowSpecComponent); |
| 215 | } | 220 | } |
| 216 | } | 221 | } |
| 217 | - return new MpUnReachNlri(new BgpFlowSpecDetails(flowSpecComponents), afi, safi); | 222 | + BgpFlowSpecDetails flowSpecDetails = new BgpFlowSpecDetails(flowSpecComponents); |
| 223 | + flowSpecDetails.setRouteDistinguiher(routeDistinguisher); | ||
| 224 | + return new MpUnReachNlri(flowSpecDetails, afi, safi); | ||
| 218 | } else { | 225 | } else { |
| 219 | //TODO: check with the values got from capability | 226 | //TODO: check with the values got from capability |
| 220 | throw new BgpParseException("Not Supporting afi " + afi + "safi " + safi); | 227 | throw new BgpParseException("Not Supporting afi " + afi + "safi " + safi); | ... | ... |
| ... | @@ -131,22 +131,29 @@ public class BgpControllerImpl implements BgpController { | ... | @@ -131,22 +131,29 @@ public class BgpControllerImpl implements BgpController { |
| 131 | } | 131 | } |
| 132 | Iterator<BgpValueType> listIterator = pathAttr.iterator(); | 132 | Iterator<BgpValueType> listIterator = pathAttr.iterator(); |
| 133 | boolean isLinkstate = false; | 133 | boolean isLinkstate = false; |
| 134 | + boolean isFlowSpec = false; | ||
| 134 | while (listIterator.hasNext()) { | 135 | while (listIterator.hasNext()) { |
| 135 | BgpValueType attr = listIterator.next(); | 136 | BgpValueType attr = listIterator.next(); |
| 136 | if (attr instanceof MpReachNlri) { | 137 | if (attr instanceof MpReachNlri) { |
| 137 | MpReachNlri mpReach = (MpReachNlri) attr; | 138 | MpReachNlri mpReach = (MpReachNlri) attr; |
| 138 | if (mpReach.bgpFlowSpecInfo() == null) { | 139 | if (mpReach.bgpFlowSpecInfo() == null) { |
| 139 | isLinkstate = true; | 140 | isLinkstate = true; |
| 141 | + } else { | ||
| 142 | + isFlowSpec = true; | ||
| 140 | } | 143 | } |
| 141 | } else if (attr instanceof MpUnReachNlri) { | 144 | } else if (attr instanceof MpUnReachNlri) { |
| 142 | MpUnReachNlri mpUnReach = (MpUnReachNlri) attr; | 145 | MpUnReachNlri mpUnReach = (MpUnReachNlri) attr; |
| 143 | if (mpUnReach.bgpFlowSpecInfo() == null) { | 146 | if (mpUnReach.bgpFlowSpecInfo() == null) { |
| 144 | isLinkstate = true; | 147 | isLinkstate = true; |
| 148 | + } else { | ||
| 149 | + isFlowSpec = true; | ||
| 145 | } | 150 | } |
| 146 | } | 151 | } |
| 147 | } | 152 | } |
| 148 | if (isLinkstate) { | 153 | if (isLinkstate) { |
| 149 | peer.buildAdjRibIn(pathAttr); | 154 | peer.buildAdjRibIn(pathAttr); |
| 155 | + } else if (isFlowSpec) { | ||
| 156 | + peer.buildFlowSpecRib(pathAttr); | ||
| 150 | } | 157 | } |
| 151 | break; | 158 | break; |
| 152 | default: | 159 | default: | ... | ... |
| ... | @@ -26,9 +26,9 @@ import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecPrefix; | ... | @@ -26,9 +26,9 @@ import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecPrefix; |
| 26 | import com.google.common.base.MoreObjects; | 26 | import com.google.common.base.MoreObjects; |
| 27 | 27 | ||
| 28 | /** | 28 | /** |
| 29 | - * Implementation of BGP flow spec RIB out for each peer. | 29 | + * Implementation of BGP flow specification RIB. |
| 30 | */ | 30 | */ |
| 31 | -public class BgpFlowSpecRibOut { | 31 | +public class BgpFlowSpecRib { |
| 32 | private Map<BgpFlowSpecPrefix, BgpFlowSpecDetails> flowSpecTree = new TreeMap<>(); | 32 | private Map<BgpFlowSpecPrefix, BgpFlowSpecDetails> flowSpecTree = new TreeMap<>(); |
| 33 | private Map<RouteDistinguisher, Map<BgpFlowSpecPrefix, BgpFlowSpecDetails>> vpnFlowSpecTree = new TreeMap<>(); | 33 | private Map<RouteDistinguisher, Map<BgpFlowSpecPrefix, BgpFlowSpecDetails>> vpnFlowSpecTree = new TreeMap<>(); |
| 34 | 34 | ... | ... |
| ... | @@ -26,6 +26,7 @@ import java.util.Set; | ... | @@ -26,6 +26,7 @@ import java.util.Set; |
| 26 | 26 | ||
| 27 | import org.jboss.netty.channel.Channel; | 27 | import org.jboss.netty.channel.Channel; |
| 28 | import org.onlab.packet.IpAddress; | 28 | import org.onlab.packet.IpAddress; |
| 29 | +import org.onlab.packet.IpPrefix; | ||
| 29 | import org.onosproject.bgp.controller.BgpController; | 30 | import org.onosproject.bgp.controller.BgpController; |
| 30 | import org.onosproject.bgp.controller.BgpLocalRib; | 31 | import org.onosproject.bgp.controller.BgpLocalRib; |
| 31 | import org.onosproject.bgp.controller.BgpPeer; | 32 | import org.onosproject.bgp.controller.BgpPeer; |
| ... | @@ -44,6 +45,8 @@ import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails; | ... | @@ -44,6 +45,8 @@ import org.onosproject.bgpio.protocol.linkstate.PathAttrNlriDetails; |
| 44 | import org.onosproject.bgpio.types.AsPath; | 45 | import org.onosproject.bgpio.types.AsPath; |
| 45 | import org.onosproject.bgpio.types.As4Path; | 46 | import org.onosproject.bgpio.types.As4Path; |
| 46 | import org.onosproject.bgpio.types.BgpExtendedCommunity; | 47 | import org.onosproject.bgpio.types.BgpExtendedCommunity; |
| 48 | +import org.onosproject.bgpio.types.BgpFsDestinationPrefix; | ||
| 49 | +import org.onosproject.bgpio.types.BgpFsSourcePrefix; | ||
| 47 | import org.onosproject.bgpio.types.BgpValueType; | 50 | import org.onosproject.bgpio.types.BgpValueType; |
| 48 | import org.onosproject.bgpio.types.LocalPref; | 51 | import org.onosproject.bgpio.types.LocalPref; |
| 49 | import org.onosproject.bgpio.types.Med; | 52 | import org.onosproject.bgpio.types.Med; |
| ... | @@ -83,25 +86,25 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -83,25 +86,25 @@ public class BgpPeerImpl implements BgpPeer { |
| 83 | private BgpLocalRib bgplocalRibVpn; | 86 | private BgpLocalRib bgplocalRibVpn; |
| 84 | private AdjRibIn adjRib; | 87 | private AdjRibIn adjRib; |
| 85 | private VpnAdjRibIn vpnAdjRib; | 88 | private VpnAdjRibIn vpnAdjRib; |
| 86 | - private BgpFlowSpecRibOut flowSpecRibOut; | 89 | + private BgpFlowSpecRib flowSpecRibOut; |
| 87 | - private BgpFlowSpecRibOut vpnFlowSpecRibOut; | 90 | + private BgpFlowSpecRib flowSpecRibIn; |
| 88 | 91 | ||
| 89 | /** | 92 | /** |
| 90 | * Returns the flowSpec RIB out. | 93 | * Returns the flowSpec RIB out. |
| 91 | * | 94 | * |
| 92 | * @return flow Specification RIB out | 95 | * @return flow Specification RIB out |
| 93 | */ | 96 | */ |
| 94 | - public BgpFlowSpecRibOut flowSpecRibOut() { | 97 | + public BgpFlowSpecRib flowSpecRibOut() { |
| 95 | return flowSpecRibOut; | 98 | return flowSpecRibOut; |
| 96 | } | 99 | } |
| 97 | 100 | ||
| 98 | /** | 101 | /** |
| 99 | - * Returns the VPN flowSpec RIB out. | 102 | + * Returns the flowSpec RIB-in. |
| 100 | * | 103 | * |
| 101 | - * @return VPN flow Specification RIB out | 104 | + * @return flow Specification RIB-in |
| 102 | */ | 105 | */ |
| 103 | - public BgpFlowSpecRibOut vpnFlowSpecRibOut() { | 106 | + public BgpFlowSpecRib flowSpecRibIn() { |
| 104 | - return vpnFlowSpecRibOut; | 107 | + return flowSpecRibIn; |
| 105 | } | 108 | } |
| 106 | 109 | ||
| 107 | /** | 110 | /** |
| ... | @@ -142,8 +145,8 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -142,8 +145,8 @@ public class BgpPeerImpl implements BgpPeer { |
| 142 | this.bgplocalRibVpn = bgpController.bgpLocalRibVpn(); | 145 | this.bgplocalRibVpn = bgpController.bgpLocalRibVpn(); |
| 143 | this.adjRib = new AdjRibIn(); | 146 | this.adjRib = new AdjRibIn(); |
| 144 | this.vpnAdjRib = new VpnAdjRibIn(); | 147 | this.vpnAdjRib = new VpnAdjRibIn(); |
| 145 | - this.flowSpecRibOut = new BgpFlowSpecRibOut(); | 148 | + this.flowSpecRibOut = new BgpFlowSpecRib(); |
| 146 | - this.vpnFlowSpecRibOut = new BgpFlowSpecRibOut(); | 149 | + this.flowSpecRibIn = new BgpFlowSpecRib(); |
| 147 | } | 150 | } |
| 148 | 151 | ||
| 149 | /** | 152 | /** |
| ... | @@ -258,21 +261,21 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -258,21 +261,21 @@ public class BgpPeerImpl implements BgpPeer { |
| 258 | } | 261 | } |
| 259 | flowSpecRibOut.add(prefix, flowSpec); | 262 | flowSpecRibOut.add(prefix, flowSpec); |
| 260 | } else { | 263 | } else { |
| 261 | - if (vpnFlowSpecRibOut.vpnFlowSpecTree().containsKey(flowSpec.routeDistinguisher())) { | 264 | + if (flowSpecRibOut.vpnFlowSpecTree().containsKey(flowSpec.routeDistinguisher())) { |
| 262 | Map<BgpFlowSpecPrefix, BgpFlowSpecDetails> fsTree; | 265 | Map<BgpFlowSpecPrefix, BgpFlowSpecDetails> fsTree; |
| 263 | - fsTree = vpnFlowSpecRibOut.vpnFlowSpecTree().get(flowSpec.routeDistinguisher()); | 266 | + fsTree = flowSpecRibOut.vpnFlowSpecTree().get(flowSpec.routeDistinguisher()); |
| 264 | if (fsTree.containsKey(prefix)) { | 267 | if (fsTree.containsKey(prefix)) { |
| 265 | sendFlowSpecUpdateMessageToPeer(FlowSpecOperation.DELETE, | 268 | sendFlowSpecUpdateMessageToPeer(FlowSpecOperation.DELETE, |
| 266 | fsTree.get(prefix)); | 269 | fsTree.get(prefix)); |
| 267 | } | 270 | } |
| 268 | } | 271 | } |
| 269 | - vpnFlowSpecRibOut.add(flowSpec.routeDistinguisher(), prefix, flowSpec); | 272 | + flowSpecRibOut.add(flowSpec.routeDistinguisher(), prefix, flowSpec); |
| 270 | } | 273 | } |
| 271 | } else if (operType == FlowSpecOperation.DELETE) { | 274 | } else if (operType == FlowSpecOperation.DELETE) { |
| 272 | if (flowSpec.routeDistinguisher() == null) { | 275 | if (flowSpec.routeDistinguisher() == null) { |
| 273 | flowSpecRibOut.delete(prefix); | 276 | flowSpecRibOut.delete(prefix); |
| 274 | } else { | 277 | } else { |
| 275 | - vpnFlowSpecRibOut.delete(flowSpec.routeDistinguisher(), prefix); | 278 | + flowSpecRibOut.delete(flowSpec.routeDistinguisher(), prefix); |
| 276 | } | 279 | } |
| 277 | } | 280 | } |
| 278 | sendFlowSpecUpdateMessageToPeer(operType, flowSpec); | 281 | sendFlowSpecUpdateMessageToPeer(operType, flowSpec); |
| ... | @@ -294,6 +297,65 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -294,6 +297,65 @@ public class BgpPeerImpl implements BgpPeer { |
| 294 | } | 297 | } |
| 295 | } | 298 | } |
| 296 | 299 | ||
| 300 | + @Override | ||
| 301 | + public void buildFlowSpecRib(List<BgpValueType> pathAttr) throws BgpParseException { | ||
| 302 | + ListIterator<BgpValueType> iterator = pathAttr.listIterator(); | ||
| 303 | + BgpFlowSpecDetails bgpFlowSpecDetails = new BgpFlowSpecDetails(); | ||
| 304 | + FlowSpecOperation operType = FlowSpecOperation.UPDATE; | ||
| 305 | + | ||
| 306 | + while (iterator.hasNext()) { | ||
| 307 | + BgpValueType attr = iterator.next(); | ||
| 308 | + if (attr instanceof MpReachNlri) { | ||
| 309 | + MpReachNlri mpReach = (MpReachNlri) attr; | ||
| 310 | + bgpFlowSpecDetails.setFlowSpecComponents(mpReach.bgpFlowSpecInfo().flowSpecComponents()); | ||
| 311 | + bgpFlowSpecDetails.setRouteDistinguiher(mpReach.bgpFlowSpecInfo().routeDistinguisher()); | ||
| 312 | + operType = FlowSpecOperation.ADD; | ||
| 313 | + } | ||
| 314 | + | ||
| 315 | + if (attr instanceof BgpExtendedCommunity) { | ||
| 316 | + BgpExtendedCommunity extCommunity = (BgpExtendedCommunity) attr; | ||
| 317 | + bgpFlowSpecDetails.setFsActionTlv(extCommunity.fsActionTlv()); | ||
| 318 | + } | ||
| 319 | + | ||
| 320 | + if (attr instanceof MpUnReachNlri) { | ||
| 321 | + MpUnReachNlri mpUnReach = (MpUnReachNlri) attr; | ||
| 322 | + bgpFlowSpecDetails.setFlowSpecComponents(mpUnReach.bgpFlowSpecInfo().flowSpecComponents()); | ||
| 323 | + bgpFlowSpecDetails.setRouteDistinguiher(mpUnReach.bgpFlowSpecInfo().routeDistinguisher()); | ||
| 324 | + operType = FlowSpecOperation.DELETE; | ||
| 325 | + } | ||
| 326 | + } | ||
| 327 | + | ||
| 328 | + iterator = bgpFlowSpecDetails.flowSpecComponents().listIterator(); | ||
| 329 | + IpPrefix destIpPrefix = null; | ||
| 330 | + IpPrefix srcIpPrefix = null; | ||
| 331 | + while (iterator.hasNext()) { | ||
| 332 | + BgpValueType fsAttr = iterator.next(); | ||
| 333 | + if (fsAttr instanceof BgpFsDestinationPrefix) { | ||
| 334 | + BgpFsDestinationPrefix destinationPrefix = (BgpFsDestinationPrefix) fsAttr; | ||
| 335 | + destIpPrefix = destinationPrefix.ipPrefix(); | ||
| 336 | + } | ||
| 337 | + | ||
| 338 | + if (fsAttr instanceof BgpFsSourcePrefix) { | ||
| 339 | + BgpFsSourcePrefix sourcePrefix = (BgpFsSourcePrefix) fsAttr; | ||
| 340 | + srcIpPrefix = sourcePrefix.ipPrefix(); | ||
| 341 | + } | ||
| 342 | + } | ||
| 343 | + BgpFlowSpecPrefix prefix = new BgpFlowSpecPrefix(destIpPrefix, srcIpPrefix); | ||
| 344 | + if (operType == FlowSpecOperation.ADD) { | ||
| 345 | + if (bgpFlowSpecDetails.routeDistinguisher() == null) { | ||
| 346 | + flowSpecRibIn.add(prefix, bgpFlowSpecDetails); | ||
| 347 | + } else { | ||
| 348 | + flowSpecRibIn.add(bgpFlowSpecDetails.routeDistinguisher(), prefix, bgpFlowSpecDetails); | ||
| 349 | + } | ||
| 350 | + } else if (operType == FlowSpecOperation.DELETE) { | ||
| 351 | + if (bgpFlowSpecDetails.routeDistinguisher() == null) { | ||
| 352 | + flowSpecRibIn.delete(prefix); | ||
| 353 | + } else { | ||
| 354 | + flowSpecRibIn.delete(bgpFlowSpecDetails.routeDistinguisher(), prefix); | ||
| 355 | + } | ||
| 356 | + } | ||
| 357 | + } | ||
| 358 | + | ||
| 297 | /** | 359 | /** |
| 298 | * Updates NLRI identifier node in a tree separately based on afi and safi. | 360 | * Updates NLRI identifier node in a tree separately based on afi and safi. |
| 299 | * | 361 | * |
| ... | @@ -447,13 +509,13 @@ public class BgpPeerImpl implements BgpPeer { | ... | @@ -447,13 +509,13 @@ public class BgpPeerImpl implements BgpPeer { |
| 447 | Constants.AFI_FLOWSPEC_VALUE, | 509 | Constants.AFI_FLOWSPEC_VALUE, |
| 448 | Constants.VPN_SAFI_FLOWSPEC_VALUE); | 510 | Constants.VPN_SAFI_FLOWSPEC_VALUE); |
| 449 | if (isVpnCapabilitySet) { | 511 | if (isVpnCapabilitySet) { |
| 450 | - Set<RouteDistinguisher> flowSpecKeys = vpnFlowSpecRibOut.vpnFlowSpecTree().keySet(); | 512 | + Set<RouteDistinguisher> flowSpecKeys = flowSpecRibOut.vpnFlowSpecTree().keySet(); |
| 451 | for (RouteDistinguisher key : flowSpecKeys) { | 513 | for (RouteDistinguisher key : flowSpecKeys) { |
| 452 | - Map<BgpFlowSpecPrefix, BgpFlowSpecDetails> fsTree = vpnFlowSpecRibOut.vpnFlowSpecTree().get(key); | 514 | + Map<BgpFlowSpecPrefix, BgpFlowSpecDetails> fsTree = flowSpecRibOut.vpnFlowSpecTree().get(key); |
| 453 | 515 | ||
| 454 | Set<BgpFlowSpecPrefix> fsKeys = fsTree.keySet(); | 516 | Set<BgpFlowSpecPrefix> fsKeys = fsTree.keySet(); |
| 455 | for (BgpFlowSpecPrefix fsKey : fsKeys) { | 517 | for (BgpFlowSpecPrefix fsKey : fsKeys) { |
| 456 | - BgpFlowSpecDetails flowSpecDetails = vpnFlowSpecRibOut.flowSpecTree().get(fsKey); | 518 | + BgpFlowSpecDetails flowSpecDetails = flowSpecRibOut.flowSpecTree().get(fsKey); |
| 457 | sendFlowSpecUpdateMessageToPeer(FlowSpecOperation.DELETE, flowSpecDetails); | 519 | sendFlowSpecUpdateMessageToPeer(FlowSpecOperation.DELETE, flowSpecDetails); |
| 458 | } | 520 | } |
| 459 | } | 521 | } | ... | ... |
| ... | @@ -18,7 +18,7 @@ package org.onosproject.controller.impl; | ... | @@ -18,7 +18,7 @@ package org.onosproject.controller.impl; |
| 18 | import org.junit.Test; | 18 | import org.junit.Test; |
| 19 | import org.onlab.packet.IpAddress; | 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.IpPrefix; | 20 | import org.onlab.packet.IpPrefix; |
| 21 | -import org.onosproject.bgp.controller.impl.BgpFlowSpecRibOut; | 21 | +import org.onosproject.bgp.controller.impl.BgpFlowSpecRib; |
| 22 | import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecDetails; | 22 | import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecDetails; |
| 23 | import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecPrefix; | 23 | import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecPrefix; |
| 24 | import org.onosproject.bgpio.types.BgpFsOperatorValue; | 24 | import org.onosproject.bgpio.types.BgpFsOperatorValue; |
| ... | @@ -36,16 +36,16 @@ import static org.hamcrest.core.Is.is; | ... | @@ -36,16 +36,16 @@ import static org.hamcrest.core.Is.is; |
| 36 | /** | 36 | /** |
| 37 | * Test cases for BGP Selection Algorithm. | 37 | * Test cases for BGP Selection Algorithm. |
| 38 | */ | 38 | */ |
| 39 | -public class BgpFlowSpecRibOutTest { | 39 | +public class BgpFlowSpecRibTest { |
| 40 | 40 | ||
| 41 | /** | 41 | /** |
| 42 | - * Add flow specification to rib out. | 42 | + * Add flow specification to rib. |
| 43 | */ | 43 | */ |
| 44 | @Test | 44 | @Test |
| 45 | - public void bgpFlowSpecRibOutTests1() { | 45 | + public void bgpFlowSpecRibTests1() { |
| 46 | List<BgpValueType> flowSpecComponents = new LinkedList<>(); | 46 | List<BgpValueType> flowSpecComponents = new LinkedList<>(); |
| 47 | List<BgpFsOperatorValue> operatorValue = new ArrayList<>(); | 47 | List<BgpFsOperatorValue> operatorValue = new ArrayList<>(); |
| 48 | - BgpFlowSpecRibOut ribOut = new BgpFlowSpecRibOut(); | 48 | + BgpFlowSpecRib rib = new BgpFlowSpecRib(); |
| 49 | 49 | ||
| 50 | IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32); | 50 | IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32); |
| 51 | IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32); | 51 | IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32); |
| ... | @@ -60,20 +60,20 @@ public class BgpFlowSpecRibOutTest { | ... | @@ -60,20 +60,20 @@ public class BgpFlowSpecRibOutTest { |
| 60 | 60 | ||
| 61 | BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents); | 61 | BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents); |
| 62 | 62 | ||
| 63 | - ribOut.add(prefix, flowSpec); | 63 | + rib.add(prefix, flowSpec); |
| 64 | 64 | ||
| 65 | - boolean isPresent = ribOut.flowSpecTree().containsKey(prefix); | 65 | + boolean isPresent = rib.flowSpecTree().containsKey(prefix); |
| 66 | assertThat(isPresent, is(true)); | 66 | assertThat(isPresent, is(true)); |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | /** | 69 | /** |
| 70 | - * Add and delete flow specification to rib out. | 70 | + * Add and delete flow specification to rib. |
| 71 | */ | 71 | */ |
| 72 | @Test | 72 | @Test |
| 73 | - public void bgpFlowSpecRibOutTest2() { | 73 | + public void bgpFlowSpecRibTest2() { |
| 74 | List<BgpValueType> flowSpecComponents = new LinkedList<>(); | 74 | List<BgpValueType> flowSpecComponents = new LinkedList<>(); |
| 75 | List<BgpFsOperatorValue> operatorValue = new ArrayList<>(); | 75 | List<BgpFsOperatorValue> operatorValue = new ArrayList<>(); |
| 76 | - BgpFlowSpecRibOut ribOut = new BgpFlowSpecRibOut(); | 76 | + BgpFlowSpecRib rib = new BgpFlowSpecRib(); |
| 77 | 77 | ||
| 78 | IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32); | 78 | IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32); |
| 79 | IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32); | 79 | IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32); |
| ... | @@ -87,26 +87,26 @@ public class BgpFlowSpecRibOutTest { | ... | @@ -87,26 +87,26 @@ public class BgpFlowSpecRibOutTest { |
| 87 | 87 | ||
| 88 | BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents); | 88 | BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents); |
| 89 | 89 | ||
| 90 | - ribOut.add(prefix, flowSpec); | 90 | + rib.add(prefix, flowSpec); |
| 91 | 91 | ||
| 92 | - boolean isPresent = ribOut.flowSpecTree().containsKey(prefix); | 92 | + boolean isPresent = rib.flowSpecTree().containsKey(prefix); |
| 93 | assertThat(isPresent, is(true)); | 93 | assertThat(isPresent, is(true)); |
| 94 | 94 | ||
| 95 | - ribOut.delete(prefix); | 95 | + rib.delete(prefix); |
| 96 | - isPresent = ribOut.flowSpecTree().containsKey(prefix); | 96 | + isPresent = rib.flowSpecTree().containsKey(prefix); |
| 97 | assertThat(isPresent, is(false)); | 97 | assertThat(isPresent, is(false)); |
| 98 | 98 | ||
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | /** | 101 | /** |
| 102 | - * Add and delete flow specification with a specific VPN to rib out. | 102 | + * Add and delete flow specification with a specific VPN to rib. |
| 103 | */ | 103 | */ |
| 104 | @Test | 104 | @Test |
| 105 | - public void bgpFlowSpecRibOutTest3() { | 105 | + public void bgpFlowSpecRibTest3() { |
| 106 | List<BgpValueType> flowSpecComponents = new LinkedList<>(); | 106 | List<BgpValueType> flowSpecComponents = new LinkedList<>(); |
| 107 | List<BgpFsOperatorValue> operatorValue = new ArrayList<>(); | 107 | List<BgpFsOperatorValue> operatorValue = new ArrayList<>(); |
| 108 | RouteDistinguisher routeDistinguisher = new RouteDistinguisher(1); | 108 | RouteDistinguisher routeDistinguisher = new RouteDistinguisher(1); |
| 109 | - BgpFlowSpecRibOut ribOut = new BgpFlowSpecRibOut(); | 109 | + BgpFlowSpecRib rib = new BgpFlowSpecRib(); |
| 110 | 110 | ||
| 111 | IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32); | 111 | IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32); |
| 112 | IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32); | 112 | IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32); |
| ... | @@ -121,13 +121,13 @@ public class BgpFlowSpecRibOutTest { | ... | @@ -121,13 +121,13 @@ public class BgpFlowSpecRibOutTest { |
| 121 | 121 | ||
| 122 | BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents); | 122 | BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents); |
| 123 | 123 | ||
| 124 | - ribOut.add(routeDistinguisher, prefix, flowSpec); | 124 | + rib.add(routeDistinguisher, prefix, flowSpec); |
| 125 | 125 | ||
| 126 | - boolean isPresent = ribOut.vpnFlowSpecTree().containsKey(routeDistinguisher); | 126 | + boolean isPresent = rib.vpnFlowSpecTree().containsKey(routeDistinguisher); |
| 127 | assertThat(isPresent, is(true)); | 127 | assertThat(isPresent, is(true)); |
| 128 | 128 | ||
| 129 | - ribOut.delete(routeDistinguisher, prefix); | 129 | + rib.delete(routeDistinguisher, prefix); |
| 130 | - isPresent = ribOut.vpnFlowSpecTree().containsKey(routeDistinguisher); | 130 | + isPresent = rib.vpnFlowSpecTree().containsKey(routeDistinguisher); |
| 131 | assertThat(isPresent, is(false)); | 131 | assertThat(isPresent, is(false)); |
| 132 | } | 132 | } |
| 133 | } | 133 | } | ... | ... |
-
Please register or login to post a comment