Jonathan Hart
Committed by Brian O'Connor

Cleaned up SDN-IP config reader

Change-Id: I98100a77b7460eeba848c2b7016f51cdcfef072a
...@@ -143,7 +143,7 @@ public class Router implements RouteListener { ...@@ -143,7 +143,7 @@ public class Router implements RouteListener {
143 } 143 }
144 144
145 /** 145 /**
146 - * Starts the Router. 146 + * Starts the router.
147 */ 147 */
148 public void start() { 148 public void start() {
149 bgpUpdatesExecutor.execute(new Runnable() { 149 bgpUpdatesExecutor.execute(new Runnable() {
...@@ -161,6 +161,14 @@ public class Router implements RouteListener { ...@@ -161,6 +161,14 @@ public class Router implements RouteListener {
161 }); 161 });
162 } 162 }
163 163
164 + /**
165 + * Shuts the router down.
166 + */
167 + public void shutdown() {
168 + bgpUpdatesExecutor.shutdownNow();
169 + bgpIntentsSynchronizerExecutor.shutdownNow();
170 + }
171 +
164 //@Override TODO hook this up to something 172 //@Override TODO hook this up to something
165 public void leaderChanged(boolean isLeader) { 173 public void leaderChanged(boolean isLeader) {
166 log.debug("Leader changed: {}", isLeader); 174 log.debug("Leader changed: {}", isLeader);
......
...@@ -90,6 +90,9 @@ public class SdnIp implements SdnIpService { ...@@ -90,6 +90,9 @@ public class SdnIp implements SdnIpService {
90 90
91 @Deactivate 91 @Deactivate
92 protected void deactivate() { 92 protected void deactivate() {
93 + bgpSessionManager.shutDown();
94 + router.shutdown();
95 +
93 log.info("Stopped"); 96 log.info("Stopped");
94 } 97 }
95 98
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onlab.onos.sdnip.config; 16 package org.onlab.onos.sdnip.config;
17 17
18 import java.io.File; 18 import java.io.File;
19 +import java.io.FileNotFoundException;
19 import java.io.IOException; 20 import java.io.IOException;
20 import java.util.Collections; 21 import java.util.Collections;
21 import java.util.Map; 22 import java.util.Map;
...@@ -40,12 +41,8 @@ public class SdnIpConfigReader implements SdnIpConfigService { ...@@ -40,12 +41,8 @@ public class SdnIpConfigReader implements SdnIpConfigService {
40 41
41 private static final String DEFAULT_CONFIG_FILE = "config/sdnip.json"; 42 private static final String DEFAULT_CONFIG_FILE = "config/sdnip.json";
42 private String configFileName = DEFAULT_CONFIG_FILE; 43 private String configFileName = DEFAULT_CONFIG_FILE;
43 - //private Map<String, Interface> interfaces; 44 + private Map<String, BgpSpeaker> bgpSpeakers = new ConcurrentHashMap<>();
44 - // We call the BGP routers in our SDN network the BGP speakers, and call 45 + private Map<IpAddress, BgpPeer> bgpPeers = new ConcurrentHashMap<>();
45 - // the BGP routers outside our SDN network the BGP peers.
46 - private Map<String, BgpSpeaker> bgpSpeakers;
47 - private Map<IpAddress, BgpPeer> bgpPeers;
48 - //private InvertedRadixTree<Interface> interfaceRoutes;
49 46
50 /** 47 /**
51 * Reads the info contained in the configuration file. 48 * Reads the info contained in the configuration file.
...@@ -58,78 +55,25 @@ public class SdnIpConfigReader implements SdnIpConfigService { ...@@ -58,78 +55,25 @@ public class SdnIpConfigReader implements SdnIpConfigService {
58 55
59 try { 56 try {
60 Configuration config = mapper.readValue(gatewaysFile, Configuration.class); 57 Configuration config = mapper.readValue(gatewaysFile, Configuration.class);
61 - /*interfaces = new ConcurrentHashMap<>();
62 - for (Interface intf : config.getInterfaces()) {
63 - interfaces.put(intf.getName(), intf);
64 - }*/
65 - bgpSpeakers = new ConcurrentHashMap<>();
66 for (BgpSpeaker speaker : config.getBgpSpeakers()) { 58 for (BgpSpeaker speaker : config.getBgpSpeakers()) {
67 bgpSpeakers.put(speaker.name(), speaker); 59 bgpSpeakers.put(speaker.name(), speaker);
68 } 60 }
69 - bgpPeers = new ConcurrentHashMap<>();
70 for (BgpPeer peer : config.getPeers()) { 61 for (BgpPeer peer : config.getPeers()) {
71 bgpPeers.put(peer.ipAddress(), peer); 62 bgpPeers.put(peer.ipAddress(), peer);
72 } 63 }
64 + } catch (FileNotFoundException e) {
65 + log.warn("Configuration file not found: {}", configFileName);
73 } catch (IOException e) { 66 } catch (IOException e) {
74 log.error("Error reading JSON file", e); 67 log.error("Error reading JSON file", e);
75 - //throw new ConfigurationRuntimeException("Error in JSON file", e);
76 } 68 }
77 -
78 - // Populate the interface InvertedRadixTree
79 - /*for (Interface intf : interfaces.values()) {
80 - Ip4Prefix prefix = intf.getIp4Prefix();
81 - String binaryString = RouteEntry.createBinaryString(prefix);
82 - interfaceRoutes.put(binaryString, intf);
83 - }*/
84 } 69 }
85 70
86 - /*
87 - * To find the Interface which has longest matchable IP prefix (sub-network
88 - * prefix) to next hop IP address.
89 - *
90 - * @param address the IP address of next hop router
91 - * @return the Interface which has longest matchable IP prefix
92 - */
93 - /*private Interface longestInterfacePrefixMatch(IpAddress address) {
94 - Ip4Prefix prefixToSearchFor =
95 - new Ip4Prefix(address, (short) Ip4Address.BIT_LENGTH);
96 - String binaryString = RouteEntry.createBinaryString(prefixToSearchFor);
97 -
98 - Iterator<Interface> it =
99 - interfaceRoutes.getValuesForKeysPrefixing(binaryString).iterator();
100 - Interface intf = null;
101 - // Find the last prefix, which will be the longest prefix
102 - while (it.hasNext()) {
103 - intf = it.next();
104 - }
105 -
106 - return intf;
107 - }*/
108 -
109 - /*@Override
110 - public Interface getOutgoingInterface(IpAddress dstIpAddress) {
111 - return longestInterfacePrefixMatch(dstIpAddress);
112 - }*/
113 -
114 public void init() { 71 public void init() {
115 - //interfaceRoutes = new ConcurrentInvertedRadixTree<>(
116 - //new DefaultByteArrayNodeFactory());
117 -
118 - // Reading config values
119 - /*String configFilenameParameter = context.getConfigParams(this).get("configfile");
120 - if (configFilenameParameter != null) {
121 - currentConfigFilename = configFilenameParameter;
122 - }*/
123 log.debug("Config file set to {}", configFileName); 72 log.debug("Config file set to {}", configFileName);
124 73
125 readConfiguration(configFileName); 74 readConfiguration(configFileName);
126 } 75 }
127 76
128 - /*@Override
129 - public Map<String, Interface> getInterfaces() {
130 - return Collections.unmodifiableMap(interfaces);
131 - }*/
132 -
133 @Override 77 @Override
134 public Map<String, BgpSpeaker> getBgpSpeakers() { 78 public Map<String, BgpSpeaker> getBgpSpeakers() {
135 return Collections.unmodifiableMap(bgpSpeakers); 79 return Collections.unmodifiableMap(bgpSpeakers);
......