Committed by
Gerrit Code Review
NullHostProvider - check for device ownership before host creation.
This is done by literal check of NodeId, as it is encoded in the DeviceId. Also includes minor fixes to config file parsing. Reference: ONOS-873 Change-Id: Id333c109c3bb752dcb78ede3a4dfd94fec189cc0
Showing
3 changed files
with
28 additions
and
10 deletions
providers/null/device/src/main/java/org/onosproject/provider/nil/device/impl/NullDeviceProvider.java
... | @@ -98,7 +98,7 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid | ... | @@ -98,7 +98,7 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid |
98 | 98 | ||
99 | private int numDevices = DEF_NUMDEVICES; | 99 | private int numDevices = DEF_NUMDEVICES; |
100 | 100 | ||
101 | - @Property(name = "numPorts", intValue = DEF_NUMPORTS, label = "Number of ports per devices") | 101 | + @Property(name = "numPorts", value = "10", label = "Number of ports per devices") |
102 | private int numPorts = DEF_NUMPORTS; | 102 | private int numPorts = DEF_NUMPORTS; |
103 | 103 | ||
104 | private DeviceCreator creator; | 104 | private DeviceCreator creator; |
... | @@ -159,6 +159,8 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid | ... | @@ -159,6 +159,8 @@ public class NullDeviceProvider extends AbstractProvider implements DeviceProvid |
159 | newPortNum = isNullOrEmpty(s) ? DEF_NUMPORTS : Integer.valueOf(s.trim()); | 159 | newPortNum = isNullOrEmpty(s) ? DEF_NUMPORTS : Integer.valueOf(s.trim()); |
160 | } catch (Exception e) { | 160 | } catch (Exception e) { |
161 | log.warn(e.getMessage()); | 161 | log.warn(e.getMessage()); |
162 | + newDevNum = numDevices; | ||
163 | + newPortNum = numPorts; | ||
162 | } | 164 | } |
163 | 165 | ||
164 | boolean chgd = false; | 166 | boolean chgd = false; | ... | ... |
... | @@ -22,6 +22,8 @@ import org.apache.felix.scr.annotations.Reference; | ... | @@ -22,6 +22,8 @@ import org.apache.felix.scr.annotations.Reference; |
22 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 22 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
23 | import org.onlab.packet.MacAddress; | 23 | import org.onlab.packet.MacAddress; |
24 | import org.onlab.packet.VlanId; | 24 | import org.onlab.packet.VlanId; |
25 | +import org.onosproject.cluster.ClusterService; | ||
26 | +import org.onosproject.mastership.MastershipService; | ||
25 | import org.onosproject.net.Device; | 27 | import org.onosproject.net.Device; |
26 | import org.onosproject.net.Host; | 28 | import org.onosproject.net.Host; |
27 | import org.onosproject.net.HostId; | 29 | import org.onosproject.net.HostId; |
... | @@ -41,6 +43,7 @@ import org.onosproject.net.provider.ProviderId; | ... | @@ -41,6 +43,7 @@ import org.onosproject.net.provider.ProviderId; |
41 | import org.slf4j.Logger; | 43 | import org.slf4j.Logger; |
42 | 44 | ||
43 | import static org.slf4j.LoggerFactory.getLogger; | 45 | import static org.slf4j.LoggerFactory.getLogger; |
46 | +import static org.onlab.util.Tools.toHex; | ||
44 | 47 | ||
45 | /** | 48 | /** |
46 | * Null provider to advertise fake hosts. | 49 | * Null provider to advertise fake hosts. |
... | @@ -54,6 +57,12 @@ public class NullHostProvider extends AbstractProvider implements HostProvider { | ... | @@ -54,6 +57,12 @@ public class NullHostProvider extends AbstractProvider implements HostProvider { |
54 | protected DeviceService deviceService; | 57 | protected DeviceService deviceService; |
55 | 58 | ||
56 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 59 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
60 | + protected MastershipService roleService; | ||
61 | + | ||
62 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
63 | + protected ClusterService nodeService; | ||
64 | + | ||
65 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
57 | protected HostProviderRegistry providerRegistry; | 66 | protected HostProviderRegistry providerRegistry; |
58 | 67 | ||
59 | private HostProviderService providerService; | 68 | private HostProviderService providerService; |
... | @@ -90,8 +99,6 @@ public class NullHostProvider extends AbstractProvider implements HostProvider { | ... | @@ -90,8 +99,6 @@ public class NullHostProvider extends AbstractProvider implements HostProvider { |
90 | log.info("Started"); | 99 | log.info("Started"); |
91 | } | 100 | } |
92 | 101 | ||
93 | - | ||
94 | - | ||
95 | @Deactivate | 102 | @Deactivate |
96 | public void deactivate() { | 103 | public void deactivate() { |
97 | providerRegistry.unregister(this); | 104 | providerRegistry.unregister(this); |
... | @@ -104,6 +111,14 @@ public class NullHostProvider extends AbstractProvider implements HostProvider { | ... | @@ -104,6 +111,14 @@ public class NullHostProvider extends AbstractProvider implements HostProvider { |
104 | public void triggerProbe(Host host) {} | 111 | public void triggerProbe(Host host) {} |
105 | 112 | ||
106 | private void addHosts(Device device) { | 113 | private void addHosts(Device device) { |
114 | + String nhash = toHex(nodeService.getLocalNode().hashCode()); | ||
115 | + String dhash = device.id().toString(); | ||
116 | + // make sure this instance owns the device. | ||
117 | + if (!nhash.substring(nhash.length() - 3) | ||
118 | + .equals(dhash.substring(14, 17))) { | ||
119 | + log.warn("Device {} is not mine. Can't add hosts.", device.id()); | ||
120 | + return; | ||
121 | + } | ||
107 | for (int i = 0; i < HOSTSPERDEVICE; i++) { | 122 | for (int i = 0; i < HOSTSPERDEVICE; i++) { |
108 | providerService.hostDetected( | 123 | providerService.hostDetected( |
109 | HostId.hostId(MacAddress.valueOf(i + device.hashCode()), | 124 | HostId.hostId(MacAddress.valueOf(i + device.hashCode()), |
... | @@ -130,8 +145,9 @@ public class NullHostProvider extends AbstractProvider implements HostProvider { | ... | @@ -130,8 +145,9 @@ public class NullHostProvider extends AbstractProvider implements HostProvider { |
130 | private class InternalHostProvider implements DeviceListener { | 145 | private class InternalHostProvider implements DeviceListener { |
131 | @Override | 146 | @Override |
132 | public void event(DeviceEvent event) { | 147 | public void event(DeviceEvent event) { |
133 | - if (!deviceService.getRole(event.subject().id()) | 148 | + Device dev = event.subject(); |
134 | - .equals(MastershipRole.MASTER)) { | 149 | + if (!deviceService.getRole(event.subject().id()).equals( |
150 | + MastershipRole.MASTER)) { | ||
135 | log.info("Local node is not master for device {}", event | 151 | log.info("Local node is not master for device {}", event |
136 | .subject().id()); | 152 | .subject().id()); |
137 | return; | 153 | return; |
... | @@ -139,12 +155,12 @@ public class NullHostProvider extends AbstractProvider implements HostProvider { | ... | @@ -139,12 +155,12 @@ public class NullHostProvider extends AbstractProvider implements HostProvider { |
139 | switch (event.type()) { | 155 | switch (event.type()) { |
140 | 156 | ||
141 | case DEVICE_ADDED: | 157 | case DEVICE_ADDED: |
142 | - addHosts(event.subject()); | 158 | + addHosts(dev); |
143 | break; | 159 | break; |
144 | case DEVICE_UPDATED: | 160 | case DEVICE_UPDATED: |
145 | break; | 161 | break; |
146 | case DEVICE_REMOVED: | 162 | case DEVICE_REMOVED: |
147 | - removeHosts(event.subject()); | 163 | + removeHosts(dev); |
148 | break; | 164 | break; |
149 | case DEVICE_SUSPENDED: | 165 | case DEVICE_SUSPENDED: |
150 | break; | 166 | break; |
... | @@ -161,6 +177,6 @@ public class NullHostProvider extends AbstractProvider implements HostProvider { | ... | @@ -161,6 +177,6 @@ public class NullHostProvider extends AbstractProvider implements HostProvider { |
161 | } | 177 | } |
162 | } | 178 | } |
163 | 179 | ||
164 | - | ||
165 | } | 180 | } |
181 | + | ||
166 | } | 182 | } | ... | ... |
... | @@ -103,12 +103,12 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider { | ... | @@ -103,12 +103,12 @@ public class NullLinkProvider extends AbstractProvider implements LinkProvider { |
103 | namedThreads("onos-null-link-driver")); | 103 | namedThreads("onos-null-link-driver")); |
104 | 104 | ||
105 | // If true, 'flickers' links by alternating link up/down events at eventRate | 105 | // If true, 'flickers' links by alternating link up/down events at eventRate |
106 | - @Property(name = "flicker", boolValue = FLICKER, | 106 | + @Property(name = "flicker", value = "false", |
107 | label = "Setting to flap links") | 107 | label = "Setting to flap links") |
108 | private boolean flicker = FLICKER; | 108 | private boolean flicker = FLICKER; |
109 | 109 | ||
110 | // For flicker = true, duration between events in msec. | 110 | // For flicker = true, duration between events in msec. |
111 | - @Property(name = "eventRate", intValue = DEFAULT_RATE, | 111 | + @Property(name = "eventRate", value = "3000", |
112 | label = "Duration between Link Event") | 112 | label = "Duration between Link Event") |
113 | private int eventRate = DEFAULT_RATE; | 113 | private int eventRate = DEFAULT_RATE; |
114 | 114 | ... | ... |
-
Please register or login to post a comment