Ayaka Koshibe
Committed by Gerrit Code Review

NullLinkProviders join network islands deterministically.

  - Added configuration parameters for order of instances.
  - got rid of 'flicker' flag since it's redundant.

Reference: ONOS-890

Change-Id: I0217e17f2a55d85e0a1fc8f2b3ea8cb54cb87517
...@@ -19,10 +19,12 @@ import static com.google.common.base.Strings.isNullOrEmpty; ...@@ -19,10 +19,12 @@ import static com.google.common.base.Strings.isNullOrEmpty;
19 import static org.onlab.util.Tools.delay; 19 import static org.onlab.util.Tools.delay;
20 import static org.onlab.util.Tools.namedThreads; 20 import static org.onlab.util.Tools.namedThreads;
21 import static org.slf4j.LoggerFactory.getLogger; 21 import static org.slf4j.LoggerFactory.getLogger;
22 +import static org.onlab.util.Tools.toHex;
22 import static org.onosproject.net.MastershipRole.MASTER; 23 import static org.onosproject.net.MastershipRole.MASTER;
23 24
24 import java.util.Dictionary; 25 import java.util.Dictionary;
25 import java.util.List; 26 import java.util.List;
27 +import java.util.Objects;
26 import java.util.concurrent.ConcurrentMap; 28 import java.util.concurrent.ConcurrentMap;
27 import java.util.concurrent.ExecutorService; 29 import java.util.concurrent.ExecutorService;
28 import java.util.concurrent.Executors; 30 import java.util.concurrent.Executors;
...@@ -35,6 +37,8 @@ import org.apache.felix.scr.annotations.Modified; ...@@ -35,6 +37,8 @@ import org.apache.felix.scr.annotations.Modified;
35 import org.apache.felix.scr.annotations.Property; 37 import org.apache.felix.scr.annotations.Property;
36 import org.apache.felix.scr.annotations.Reference; 38 import org.apache.felix.scr.annotations.Reference;
37 import org.apache.felix.scr.annotations.ReferenceCardinality; 39 import org.apache.felix.scr.annotations.ReferenceCardinality;
40 +import org.onosproject.cluster.ClusterService;
41 +import org.onosproject.cluster.NodeId;
38 import org.onosproject.mastership.MastershipService; 42 import org.onosproject.mastership.MastershipService;
39 import org.onosproject.net.ConnectPoint; 43 import org.onosproject.net.ConnectPoint;
40 import org.onosproject.net.Device; 44 import org.onosproject.net.Device;
...@@ -76,13 +80,15 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -76,13 +80,15 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider {
76 protected MastershipService roleService; 80 protected MastershipService roleService;
77 81
78 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 82 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
83 + protected ClusterService nodeService;
84 +
85 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
79 protected LinkProviderRegistry providerRegistry; 86 protected LinkProviderRegistry providerRegistry;
80 private LinkService linkService; 87 private LinkService linkService;
81 88
82 private LinkProviderService providerService; 89 private LinkProviderService providerService;
83 90
84 - private static final boolean FLICKER = false; 91 + private static final int DEFAULT_RATE = 0;
85 - private static final int DEFAULT_RATE = 3000;
86 // For now, static switch port values 92 // For now, static switch port values
87 private static final PortNumber SRCPORT = PortNumber.portNumber(5); 93 private static final PortNumber SRCPORT = PortNumber.portNumber(5);
88 private static final PortNumber DSTPORT = PortNumber.portNumber(6); 94 private static final PortNumber DSTPORT = PortNumber.portNumber(6);
...@@ -102,16 +108,16 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -102,16 +108,16 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider {
102 private ExecutorService linkDriver = Executors.newFixedThreadPool(1, 108 private ExecutorService linkDriver = Executors.newFixedThreadPool(1,
103 namedThreads("onos-null-link-driver")); 109 namedThreads("onos-null-link-driver"));
104 110
105 - // If true, 'flickers' links by alternating link up/down events at eventRate
106 - @Property(name = "flicker", value = "false",
107 - label = "Setting to flap links")
108 - private boolean flicker = FLICKER;
109 -
110 // For flicker = true, duration between events in msec. 111 // For flicker = true, duration between events in msec.
111 - @Property(name = "eventRate", value = "3000", 112 + @Property(name = "eventRate", value = "0",
112 label = "Duration between Link Event") 113 label = "Duration between Link Event")
113 private int eventRate = DEFAULT_RATE; 114 private int eventRate = DEFAULT_RATE;
114 115
116 + // For flicker = true, duration between events in msec.
117 + @Property(name = "neighbors", value = "",
118 + label = "Node ID of instance for neighboring island ")
119 + private String neighbor = "";
120 +
115 public NullLinkProvider() { 121 public NullLinkProvider() {
116 super(new ProviderId("null", "org.onosproject.provider.nil")); 122 super(new ProviderId("null", "org.onosproject.provider.nil"));
117 } 123 }
...@@ -128,7 +134,7 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -128,7 +134,7 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider {
128 134
129 @Deactivate 135 @Deactivate
130 public void deactivate(ComponentContext context) { 136 public void deactivate(ComponentContext context) {
131 - if (flicker) { 137 + if (eventRate != 0) {
132 try { 138 try {
133 linkDriver.awaitTermination(1000, TimeUnit.MILLISECONDS); 139 linkDriver.awaitTermination(1000, TimeUnit.MILLISECONDS);
134 } catch (InterruptedException e) { 140 } catch (InterruptedException e) {
...@@ -148,37 +154,34 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -148,37 +154,34 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider {
148 @Modified 154 @Modified
149 public void modified(ComponentContext context) { 155 public void modified(ComponentContext context) {
150 if (context == null) { 156 if (context == null) {
151 - log.info("No configs, using defaults: flicker={}, eventRate={}", 157 + log.info("No configs, using defaults: eventRate={}", DEFAULT_RATE);
152 - FLICKER, DEFAULT_RATE);
153 return; 158 return;
154 } 159 }
155 Dictionary<?, ?> properties = context.getProperties(); 160 Dictionary<?, ?> properties = context.getProperties();
156 161
157 - boolean flickSetting;
158 int newRate; 162 int newRate;
163 + String newNbor;
159 try { 164 try {
160 - String s = (String) properties.get("flicker"); 165 + String s = (String) properties.get("eventRate");
161 - flickSetting = isNullOrEmpty(s) ? flicker : Boolean.valueOf(s.trim());
162 - s = (String) properties.get("eventRate");
163 newRate = isNullOrEmpty(s) ? eventRate : Integer.valueOf(s.trim()); 166 newRate = isNullOrEmpty(s) ? eventRate : Integer.valueOf(s.trim());
167 + s = (String) properties.get("neighbors");
168 + newNbor = isNullOrEmpty(s) ? neighbor : getNeighbor(s.trim());
164 } catch (Exception e) { 169 } catch (Exception e) {
165 log.warn(e.getMessage()); 170 log.warn(e.getMessage());
166 - flickSetting = flicker;
167 newRate = eventRate; 171 newRate = eventRate;
172 + newNbor = neighbor;
168 } 173 }
169 174
170 - if (flicker != flickSetting) { 175 + if (newNbor != neighbor) {
171 - flicker = flickSetting; 176 + neighbor = newNbor;
172 } 177 }
173 178
174 - if (flicker) { 179 + if (newRate != 0 & eventRate != newRate) {
175 - if (eventRate != newRate) { 180 + eventRate = newRate;
176 - eventRate = newRate;
177 - }
178 linkDriver.submit(new LinkDriver()); 181 linkDriver.submit(new LinkDriver());
179 } 182 }
180 - log.info("Using new settings: flicker={}, eventRate={}", flicker, 183 +
181 - eventRate); 184 + log.info("Using new settings: eventRate={}", eventRate);
182 } 185 }
183 186
184 // pick out substring from Deviceid 187 // pick out substring from Deviceid
...@@ -186,6 +189,30 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -186,6 +189,30 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider {
186 return devId.split(":")[1].substring(12, 16); 189 return devId.split(":")[1].substring(12, 16);
187 } 190 }
188 191
192 + // pick out substring from Deviceid
193 + private String nIdPart(String devId) {
194 + return devId.split(":")[1].substring(9, 12);
195 + }
196 +
197 + // pick out the next node ID in string, return hash (i.e. what's
198 + // in a Device ID
199 + private String getNeighbor(String nbors) {
200 + String me = nodeService.getLocalNode().id().toString();
201 + String mynb = "";
202 + String[] nodes = nbors.split(",");
203 + for (int i = 0; i < nodes.length; i++) {
204 + if (i != 0 & nodes[i].equals(me)) {
205 + mynb = nodes[i - 1];
206 + break;
207 + }
208 + }
209 + // return as hash string.
210 + if (!mynb.isEmpty()) {
211 + return toHex((Objects.hash(new NodeId(mynb)))).substring(13, 16);
212 + }
213 + return "";
214 + }
215 +
189 /** 216 /**
190 * Adds links as devices are found, and generates LinkEvents. 217 * Adds links as devices are found, and generates LinkEvents.
191 */ 218 */
...@@ -209,9 +236,11 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -209,9 +236,11 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider {
209 private void addLink(Device current) { 236 private void addLink(Device current) {
210 DeviceId did = current.id(); 237 DeviceId did = current.id();
211 if (!MASTER.equals(roleService.getLocalRole(did))) { 238 if (!MASTER.equals(roleService.getLocalRole(did))) {
239 +
212 String part = part(did.toString()); 240 String part = part(did.toString());
213 - if (part.equals("ffff")) { 241 + String npart = nIdPart(did.toString());
214 - // 'tail' of an island - link us <- tail 242 + if (part.equals("ffff") & npart.equals(neighbor)) {
243 + // 'tail' of our neighboring island - link us <- tail
215 tails.add(new ConnectPoint(did, SRCPORT)); 244 tails.add(new ConnectPoint(did, SRCPORT));
216 } 245 }
217 tryLinkTail(); 246 tryLinkTail();
......
1 # Sample configurations for the NullLinkProvider. 1 # Sample configurations for the NullLinkProvider.
2 2
3 # 3 #
4 -# If enabled, generates LinkDetected and LinkVanished events
5 -# to make the link appear to be flapping.
6 -#
7 -# flicker = true
8 -
9 -#
10 # If enabled, sets the time between LinkEvent generation, 4 # If enabled, sets the time between LinkEvent generation,
11 # in milliseconds. 5 # in milliseconds.
12 # 6 #
13 # eventRate = 2000 7 # eventRate = 2000
8 +
9 +#
10 +# Set order of islands to chain together, in a line.
11 +#
12 +neighbors = 192.168.56.20,192.168.56.30,192.168.56.40
......