Committed by
ShashikanthVH-Huawei
[ONOS-3856] Implement BGP flow spec RIB out.
Change-Id: I2fa378851ea1b953def3d8feeedbc50cfe4d50ca
Showing
1 changed file
with
127 additions
and
0 deletions
protocols/bgp/ctl/src/main/java/org/onosproject/bgp/controller/impl/BgpFlowSpecRibOut.java
0 → 100755
1 | +/* | ||
2 | + * Copyright 2016 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 | + | ||
17 | +package org.onosproject.bgp.controller.impl; | ||
18 | + | ||
19 | +import java.util.Map; | ||
20 | +import java.util.TreeMap; | ||
21 | + | ||
22 | +import org.onosproject.bgpio.types.RouteDistinguisher; | ||
23 | +import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecDetails; | ||
24 | +import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecPrefix; | ||
25 | + | ||
26 | +import com.google.common.base.MoreObjects; | ||
27 | + | ||
28 | +/** | ||
29 | + * Implementation of BGP flow spec RIB out for each peer. | ||
30 | + */ | ||
31 | +public class BgpFlowSpecRibOut { | ||
32 | + private Map<BgpFlowSpecPrefix, BgpFlowSpecDetails> flowSpecTree = new TreeMap<>(); | ||
33 | + private Map<RouteDistinguisher, Map<BgpFlowSpecPrefix, BgpFlowSpecDetails>> vpnFlowSpecTree = new TreeMap<>(); | ||
34 | + | ||
35 | + /** | ||
36 | + * Returns the BGP flow spec info. | ||
37 | + * | ||
38 | + * @return BGP flow spec tree | ||
39 | + */ | ||
40 | + public Map<BgpFlowSpecPrefix, BgpFlowSpecDetails> flowSpecTree() { | ||
41 | + return flowSpecTree; | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * Gets VPN flowspec tree. | ||
46 | + * | ||
47 | + * @return vpn flow spec tree | ||
48 | + */ | ||
49 | + public Map<RouteDistinguisher, Map<BgpFlowSpecPrefix, BgpFlowSpecDetails>> vpnFlowSpecTree() { | ||
50 | + return vpnFlowSpecTree; | ||
51 | + } | ||
52 | + | ||
53 | + | ||
54 | + /** | ||
55 | + * Update BGP flow spec details. | ||
56 | + * | ||
57 | + * @param prefix prefix Info | ||
58 | + * @param flowSpec BGP flow specifications details | ||
59 | + */ | ||
60 | + public void add(BgpFlowSpecPrefix prefix, BgpFlowSpecDetails flowSpec) { | ||
61 | + if (flowSpecTree.containsKey(prefix)) { | ||
62 | + flowSpecTree.replace(prefix, flowSpec); | ||
63 | + } else { | ||
64 | + flowSpecTree.put(prefix, flowSpec); | ||
65 | + } | ||
66 | + } | ||
67 | + | ||
68 | + /** | ||
69 | + * Removes flow spec. | ||
70 | + * | ||
71 | + * @param flowSpec BGP flow specification | ||
72 | + */ | ||
73 | + public void delete(BgpFlowSpecPrefix flowSpec) { | ||
74 | + if (flowSpecTree.containsKey(flowSpec)) { | ||
75 | + flowSpecTree.remove(flowSpec); | ||
76 | + } | ||
77 | + } | ||
78 | + | ||
79 | + /** | ||
80 | + * Update BGP flow spec details with routedistinguisher. | ||
81 | + * | ||
82 | + * @param routeDistinguisher route distinguisher | ||
83 | + * @param prefix prefix Info | ||
84 | + * @param flowSpec BGP flow specifications details | ||
85 | + */ | ||
86 | + public void add(RouteDistinguisher routeDistinguisher, BgpFlowSpecPrefix prefix, BgpFlowSpecDetails flowSpec) { | ||
87 | + Map<BgpFlowSpecPrefix, BgpFlowSpecDetails> fsTree; | ||
88 | + if (!vpnFlowSpecTree.containsKey(routeDistinguisher)) { | ||
89 | + | ||
90 | + fsTree = new TreeMap<>(); | ||
91 | + | ||
92 | + vpnFlowSpecTree.put(routeDistinguisher, fsTree); | ||
93 | + } else { | ||
94 | + fsTree = vpnFlowSpecTree().get(routeDistinguisher); | ||
95 | + } | ||
96 | + if (fsTree.containsKey(prefix)) { | ||
97 | + fsTree.replace(prefix, flowSpec); | ||
98 | + } else { | ||
99 | + fsTree.put(prefix, flowSpec); | ||
100 | + } | ||
101 | + } | ||
102 | + | ||
103 | + /** | ||
104 | + * Removes flow spec. | ||
105 | + * | ||
106 | + * @param routeDistinguisher route distinguisher | ||
107 | + * @param flowSpec BGP flow specification | ||
108 | + */ | ||
109 | + public void delete(RouteDistinguisher routeDistinguisher, BgpFlowSpecPrefix flowSpecPrefix) { | ||
110 | + if (vpnFlowSpecTree.containsKey(routeDistinguisher)) { | ||
111 | + Map<BgpFlowSpecPrefix, BgpFlowSpecDetails> fsTree = vpnFlowSpecTree().get(routeDistinguisher); | ||
112 | + fsTree.remove(flowSpecPrefix); | ||
113 | + if (fsTree.size() == 0) { | ||
114 | + vpnFlowSpecTree.remove(routeDistinguisher); | ||
115 | + } | ||
116 | + } | ||
117 | + } | ||
118 | + | ||
119 | + @Override | ||
120 | + public String toString() { | ||
121 | + return MoreObjects.toStringHelper(getClass()) | ||
122 | + .omitNullValues() | ||
123 | + .add("flowSpecTree", flowSpecTree) | ||
124 | + .add("vpnFlowSpecTree", vpnFlowSpecTree) | ||
125 | + .toString(); | ||
126 | + } | ||
127 | +} |
-
Please register or login to post a comment