Committed by
Gerrit Code Review
Implementing Bgp update configuration
Change-Id: I02338d5db093c513f1048bdafd737feea81d4efb
Showing
1 changed file
with
95 additions
and
1 deletions
... | @@ -22,6 +22,7 @@ import org.apache.felix.scr.annotations.Reference; | ... | @@ -22,6 +22,7 @@ import org.apache.felix.scr.annotations.Reference; |
22 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
23 | 23 | ||
24 | import org.onosproject.bgp.controller.BgpCfg; | 24 | import org.onosproject.bgp.controller.BgpCfg; |
25 | +import org.onosproject.bgp.controller.BgpPeerCfg; | ||
25 | import org.onosproject.core.ApplicationId; | 26 | import org.onosproject.core.ApplicationId; |
26 | import org.onosproject.core.CoreService; | 27 | import org.onosproject.core.CoreService; |
27 | import org.onosproject.net.config.ConfigFactory; | 28 | import org.onosproject.net.config.ConfigFactory; |
... | @@ -36,7 +37,12 @@ import org.onosproject.bgp.controller.BgpController; | ... | @@ -36,7 +37,12 @@ import org.onosproject.bgp.controller.BgpController; |
36 | import org.slf4j.Logger; | 37 | import org.slf4j.Logger; |
37 | import org.osgi.service.component.ComponentContext; | 38 | import org.osgi.service.component.ComponentContext; |
38 | 39 | ||
40 | +import java.util.ArrayList; | ||
41 | +import java.util.Iterator; | ||
39 | import java.util.List; | 42 | import java.util.List; |
43 | +import java.util.Map; | ||
44 | +import java.util.Set; | ||
45 | +import java.util.TreeMap; | ||
40 | 46 | ||
41 | import static org.slf4j.LoggerFactory.getLogger; | 47 | import static org.slf4j.LoggerFactory.getLogger; |
42 | 48 | ||
... | @@ -86,6 +92,7 @@ public class BgpCfgProvider extends AbstractProvider { | ... | @@ -86,6 +92,7 @@ public class BgpCfgProvider extends AbstractProvider { |
86 | appId = coreService.registerApplication(PROVIDER_ID); | 92 | appId = coreService.registerApplication(PROVIDER_ID); |
87 | configService.addListener(configListener); | 93 | configService.addListener(configListener); |
88 | configRegistry.registerConfigFactory(configFactory); | 94 | configRegistry.registerConfigFactory(configFactory); |
95 | + readConfiguration(); | ||
89 | log.info("BGP cfg provider started"); | 96 | log.info("BGP cfg provider started"); |
90 | } | 97 | } |
91 | 98 | ||
... | @@ -134,6 +141,93 @@ public class BgpCfgProvider extends AbstractProvider { | ... | @@ -134,6 +141,93 @@ public class BgpCfgProvider extends AbstractProvider { |
134 | } | 141 | } |
135 | 142 | ||
136 | /** | 143 | /** |
144 | + * Read the configuration and update it to the BGP-LS south bound protocol. | ||
145 | + */ | ||
146 | + private void updateConfiguration() { | ||
147 | + BgpCfg bgpConfig = null; | ||
148 | + List<BgpAppConfig.BgpPeerConfig> nodes; | ||
149 | + TreeMap<String, BgpPeerCfg> bgpPeerTree; | ||
150 | + bgpConfig = bgpController.getConfig(); | ||
151 | + BgpPeerCfg peer = null; | ||
152 | + BgpAppConfig config = configRegistry.getConfig(appId, BgpAppConfig.class); | ||
153 | + | ||
154 | + if (config == null) { | ||
155 | + log.warn("No configuration found"); | ||
156 | + return; | ||
157 | + } | ||
158 | + | ||
159 | + | ||
160 | + /* Update the self configuration */ | ||
161 | + if (bgpController.connectedPeerCount() == 0) { | ||
162 | + bgpConfig.setRouterId(config.routerId()); | ||
163 | + bgpConfig.setAsNumber(config.localAs()); | ||
164 | + bgpConfig.setLsCapability(config.lsCapability()); | ||
165 | + bgpConfig.setHoldTime(config.holdTime()); | ||
166 | + bgpConfig.setMaxSession(config.maxSession()); | ||
167 | + bgpConfig.setLargeASCapability(config.largeAsCapability()); | ||
168 | + } else { | ||
169 | + log.info(" Self configuration cannot be modified as there is existing connections "); | ||
170 | + } | ||
171 | + | ||
172 | + /* update the peer configuration */ | ||
173 | + bgpPeerTree = bgpConfig.getPeerTree(); | ||
174 | + if (bgpPeerTree.isEmpty()) { | ||
175 | + log.info("There are no BGP peers to iterate"); | ||
176 | + } else { | ||
177 | + Set set = bgpPeerTree.entrySet(); | ||
178 | + Iterator i = set.iterator(); | ||
179 | + List<BgpPeerCfg> absPeerList = new ArrayList<BgpPeerCfg>(); | ||
180 | + | ||
181 | + boolean exists = false; | ||
182 | + | ||
183 | + while (i.hasNext()) { | ||
184 | + Map.Entry me = (Map.Entry) i.next(); | ||
185 | + peer = (BgpPeerCfg) me.getValue(); | ||
186 | + | ||
187 | + nodes = config.bgpPeer(); | ||
188 | + for (int j = 0; j < nodes.size(); j++) { | ||
189 | + String peerIp = nodes.get(j).hostname(); | ||
190 | + if (peerIp.equals(peer.getPeerRouterId())) { | ||
191 | + | ||
192 | + if (bgpConfig.isPeerConnectable(peer.getPeerRouterId())) { | ||
193 | + peer.setAsNumber(nodes.get(j).asNumber()); | ||
194 | + peer.setHoldtime(nodes.get(j).holdTime()); | ||
195 | + log.debug("Peer neighbor IP successfully modified :" + peer.getPeerRouterId()); | ||
196 | + } else { | ||
197 | + log.debug("Peer neighbor IP cannot be modified :" + peer.getPeerRouterId()); | ||
198 | + } | ||
199 | + | ||
200 | + nodes.remove(j); | ||
201 | + exists = true; | ||
202 | + break; | ||
203 | + } | ||
204 | + } | ||
205 | + | ||
206 | + if (!exists) { | ||
207 | + absPeerList.add(peer); | ||
208 | + exists = false; | ||
209 | + } | ||
210 | + } | ||
211 | + | ||
212 | + /* Remove the absent nodes. */ | ||
213 | + for (int j = 0; j < absPeerList.size(); j++) { | ||
214 | + bgpConfig.removePeer(absPeerList.get(j).getPeerRouterId()); | ||
215 | + } | ||
216 | + } | ||
217 | + | ||
218 | + | ||
219 | + nodes = config.bgpPeer(); | ||
220 | + for (int i = 0; i < nodes.size(); i++) { | ||
221 | + String connectMode = nodes.get(i).connectMode(); | ||
222 | + bgpConfig.addPeer(nodes.get(i).hostname(), nodes.get(i).asNumber(), nodes.get(i).holdTime()); | ||
223 | + if (connectMode.equals(BgpAppConfig.PEER_CONNECT_ACTIVE)) { | ||
224 | + bgpConfig.connectPeer(nodes.get(i).hostname()); | ||
225 | + } | ||
226 | + } | ||
227 | + | ||
228 | + } | ||
229 | + | ||
230 | + /** | ||
137 | * BGP config listener to populate the configuration. | 231 | * BGP config listener to populate the configuration. |
138 | */ | 232 | */ |
139 | private class InternalConfigListener implements NetworkConfigListener { | 233 | private class InternalConfigListener implements NetworkConfigListener { |
... | @@ -149,7 +243,7 @@ public class BgpCfgProvider extends AbstractProvider { | ... | @@ -149,7 +243,7 @@ public class BgpCfgProvider extends AbstractProvider { |
149 | readConfiguration(); | 243 | readConfiguration(); |
150 | break; | 244 | break; |
151 | case CONFIG_UPDATED: | 245 | case CONFIG_UPDATED: |
152 | - readConfiguration(); | 246 | + updateConfiguration(); |
153 | break; | 247 | break; |
154 | case CONFIG_REMOVED: | 248 | case CONFIG_REMOVED: |
155 | default: | 249 | default: | ... | ... |
-
Please register or login to post a comment