Pavlin Radoslavov

Cleanup in the SDN-IP related configuration files:

 * The (deployed) Interface addresses configuration file "addresses.json"
   from the apps/config application is expected to be found in the
   /opt/onos/config directory

 * The (deployed) SDN-IP configuration file "sdnip.json" is expected
   to be found in the /opt/onos/config directory

 * All configuration files (i.e., addresses.json and sdnip.json) should
   be stored in the tools/package/config directory before deployment
   (i.e., before running onos-config)

 * Removed the apps/config/src/main/resources/config.json sample configuration
   file, because it was incorrect, and replaced it with "addresses.json"
   file in the same directory

 * Updated the text in files tools/package/config/README and
   apps/sdnip/src/main/resources/config-examples/README

 * Minor code cleanup in SdnIpConfigReader.java and NetworkConfigReader.java

Change-Id: I8af75e62a94e4fb701e2c6a09cde93cd8461e255
...@@ -50,7 +50,10 @@ public class NetworkConfigReader { ...@@ -50,7 +50,10 @@ public class NetworkConfigReader {
50 50
51 private final Logger log = getLogger(getClass()); 51 private final Logger log = getLogger(getClass());
52 52
53 - private static final String DEFAULT_CONFIG_FILE = "config/addresses.json"; 53 + // Current working dir seems to be /opt/onos/apache-karaf-3.0.2
54 + // TODO: Set the path to /opt/onos/config
55 + private static final String CONFIG_DIR = "../config";
56 + private static final String DEFAULT_CONFIG_FILE = "addresses.json";
54 private String configFileName = DEFAULT_CONFIG_FILE; 57 private String configFileName = DEFAULT_CONFIG_FILE;
55 58
56 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 59 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
...@@ -60,19 +63,53 @@ public class NetworkConfigReader { ...@@ -60,19 +63,53 @@ public class NetworkConfigReader {
60 protected void activate() { 63 protected void activate() {
61 log.info("Started network config reader"); 64 log.info("Started network config reader");
62 65
63 - log.info("Config file set to {}", configFileName);
64 -
65 AddressConfiguration config = readNetworkConfig(); 66 AddressConfiguration config = readNetworkConfig();
66 -
67 if (config != null) { 67 if (config != null) {
68 - for (AddressEntry entry : config.getAddresses()) { 68 + applyNetworkConfig(config);
69 + }
70 + }
71 +
72 + @Deactivate
73 + protected void deactivate() {
74 + log.info("Stopped");
75 + }
76 +
77 + /**
78 + * Reads the network configuration.
79 + *
80 + * @return the network configuration on success, otherwise null
81 + */
82 + private AddressConfiguration readNetworkConfig() {
83 + File configFile = new File(CONFIG_DIR, configFileName);
84 + ObjectMapper mapper = new ObjectMapper();
85 +
86 + try {
87 + log.info("Loading config: {}", configFile.getAbsolutePath());
88 + AddressConfiguration config =
89 + mapper.readValue(configFile, AddressConfiguration.class);
90 +
91 + return config;
92 + } catch (FileNotFoundException e) {
93 + log.warn("Configuration file not found: {}", configFileName);
94 + } catch (IOException e) {
95 + log.error("Error loading configuration", e);
96 + }
97 +
98 + return null;
99 + }
69 100
101 + /**
102 + * Applies the network configuration.
103 + *
104 + * @param config the network configuration to apply
105 + */
106 + private void applyNetworkConfig(AddressConfiguration config) {
107 + for (AddressEntry entry : config.getAddresses()) {
70 ConnectPoint cp = new ConnectPoint( 108 ConnectPoint cp = new ConnectPoint(
71 DeviceId.deviceId(dpidToUri(entry.getDpid())), 109 DeviceId.deviceId(dpidToUri(entry.getDpid())),
72 PortNumber.portNumber(entry.getPortNumber())); 110 PortNumber.portNumber(entry.getPortNumber()));
73 111
74 Set<InterfaceIpAddress> interfaceIpAddresses = new HashSet<>(); 112 Set<InterfaceIpAddress> interfaceIpAddresses = new HashSet<>();
75 -
76 for (String strIp : entry.getIpAddresses()) { 113 for (String strIp : entry.getIpAddresses()) {
77 // Get the IP address and the subnet mask length 114 // Get the IP address and the subnet mask length
78 try { 115 try {
...@@ -103,35 +140,9 @@ public class NetworkConfigReader { ...@@ -103,35 +140,9 @@ public class NetworkConfigReader {
103 140
104 PortAddresses addresses = new PortAddresses(cp, 141 PortAddresses addresses = new PortAddresses(cp,
105 interfaceIpAddresses, macAddress); 142 interfaceIpAddresses, macAddress);
106 -
107 hostAdminService.bindAddressesToPort(addresses); 143 hostAdminService.bindAddressesToPort(addresses);
108 } 144 }
109 } 145 }
110 - }
111 -
112 - @Deactivate
113 - protected void deactivate() {
114 - log.info("Stopped");
115 - }
116 -
117 - private AddressConfiguration readNetworkConfig() {
118 - File configFile = new File(configFileName);
119 -
120 - ObjectMapper mapper = new ObjectMapper();
121 -
122 - try {
123 - AddressConfiguration config =
124 - mapper.readValue(configFile, AddressConfiguration.class);
125 -
126 - return config;
127 - } catch (FileNotFoundException e) {
128 - log.warn("Configuration file not found: {}", configFileName);
129 - } catch (IOException e) {
130 - log.error("Unable to read config from file:", e);
131 - }
132 -
133 - return null;
134 - }
135 146
136 private static String dpidToUri(String dpid) { 147 private static String dpidToUri(String dpid) {
137 return "of:" + dpid.replace(":", ""); 148 return "of:" + dpid.replace(":", "");
......
1 -{
2 - "interfaces" : [
3 - {
4 - "dpid" : "00:00:00:00:00:00:01",
5 - "port" : "1",
6 - "ips" : ["192.168.10.101/24"],
7 - "mac" : "00:00:00:11:22:33"
8 - },
9 - {
10 - "dpid" : "00:00:00:00:00:00:02",
11 - "port" : "1",
12 - "ips" : ["192.168.20.101/24", "192.168.30.101/24"]
13 - },
14 - {
15 - "dpid" : "00:00:00:00:00:00:03",
16 - "port" : "1",
17 - "ips" : ["10.1.0.1/16"],
18 - "mac" : "00:00:00:00:00:01"
19 - }
20 - ]
21 -}
...@@ -37,24 +37,31 @@ import com.fasterxml.jackson.databind.ObjectMapper; ...@@ -37,24 +37,31 @@ import com.fasterxml.jackson.databind.ObjectMapper;
37 */ 37 */
38 public class SdnIpConfigReader implements SdnIpConfigService { 38 public class SdnIpConfigReader implements SdnIpConfigService {
39 39
40 - private static final Logger log = LoggerFactory.getLogger(SdnIpConfigReader.class); 40 + private final Logger log = LoggerFactory.getLogger(getClass());
41 41
42 - private static final String DEFAULT_CONFIG_FILE = "config/sdnip.json"; 42 + // Current working dir seems to be /opt/onos/apache-karaf-3.0.2
43 + // TODO: Set the path to /opt/onos/config
44 + private static final String CONFIG_DIR = "../config";
45 + private static final String DEFAULT_CONFIG_FILE = "sdnip.json";
43 private String configFileName = DEFAULT_CONFIG_FILE; 46 private String configFileName = DEFAULT_CONFIG_FILE;
47 +
44 private Map<String, BgpSpeaker> bgpSpeakers = new ConcurrentHashMap<>(); 48 private Map<String, BgpSpeaker> bgpSpeakers = new ConcurrentHashMap<>();
45 private Map<IpAddress, BgpPeer> bgpPeers = new ConcurrentHashMap<>(); 49 private Map<IpAddress, BgpPeer> bgpPeers = new ConcurrentHashMap<>();
46 50
47 /** 51 /**
48 - * Reads the info contained in the configuration file. 52 + * Reads SDN-IP related information contained in the configuration file.
49 * 53 *
50 - * @param configFilename The name of configuration file for SDN-IP application. 54 + * @param configFilename the name of the configuration file for the SDN-IP
55 + * application
51 */ 56 */
52 private void readConfiguration(String configFilename) { 57 private void readConfiguration(String configFilename) {
53 - File gatewaysFile = new File(configFilename); 58 + File configFile = new File(CONFIG_DIR, configFilename);
54 ObjectMapper mapper = new ObjectMapper(); 59 ObjectMapper mapper = new ObjectMapper();
55 60
56 try { 61 try {
57 - Configuration config = mapper.readValue(gatewaysFile, Configuration.class); 62 + log.info("Loading config: {}", configFile.getAbsolutePath());
63 + Configuration config = mapper.readValue(configFile,
64 + Configuration.class);
58 for (BgpSpeaker speaker : config.getBgpSpeakers()) { 65 for (BgpSpeaker speaker : config.getBgpSpeakers()) {
59 bgpSpeakers.put(speaker.name(), speaker); 66 bgpSpeakers.put(speaker.name(), speaker);
60 } 67 }
...@@ -64,13 +71,11 @@ public class SdnIpConfigReader implements SdnIpConfigService { ...@@ -64,13 +71,11 @@ public class SdnIpConfigReader implements SdnIpConfigService {
64 } catch (FileNotFoundException e) { 71 } catch (FileNotFoundException e) {
65 log.warn("Configuration file not found: {}", configFileName); 72 log.warn("Configuration file not found: {}", configFileName);
66 } catch (IOException e) { 73 } catch (IOException e) {
67 - log.error("Error reading JSON file", e); 74 + log.error("Error loading configuration", e);
68 } 75 }
69 } 76 }
70 77
71 public void init() { 78 public void init() {
72 - log.debug("Config file set to {}", configFileName);
73 -
74 readConfiguration(configFileName); 79 readConfiguration(configFileName);
75 } 80 }
76 81
......
1 -ONOS looks for these config files by default in $KARAF_HOME/config/
...\ No newline at end of file ...\ No newline at end of file
1 +The SDN-IP configuration files should be copied to directory
2 + $ONOS_HOME/tools/package/config
3 +
4 +After deployment and starting up the ONOS cluster, ONOS looks for these
5 +configuration files in /opt/onos/config on each cluster member.
......
1 -onos-config command will copy files contained in this directory to ONOS instances according to cell definition 1 +The onos-config command will copy files contained in this directory to ONOS
2 - 2 +instances according to cell definition.
......