Yuta HIGUCHI

extract DeviceId

Change-Id: I1379ca26846e75b1c60fc523cae87539b3fa22db
...@@ -127,18 +127,19 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -127,18 +127,19 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
127 return; 127 return;
128 } 128 }
129 log.trace("{} {} {}", event.type(), event.subject(), event); 129 log.trace("{} {} {}", event.type(), event.subject(), event);
130 + final DeviceId deviceId = device.id();
130 switch (event.type()) { 131 switch (event.type()) {
131 case DEVICE_ADDED: 132 case DEVICE_ADDED:
132 case DEVICE_UPDATED: 133 case DEVICE_UPDATED:
133 - ld = discoverers.get(device.id()); 134 + ld = discoverers.get(deviceId);
134 if (ld == null) { 135 if (ld == null) {
135 - log.debug("Device added ({}) {}", event.type(), device.id()); 136 + log.debug("Device added ({}) {}", event.type(), deviceId);
136 - discoverers.put(device.id(), 137 + discoverers.put(deviceId,
137 new LinkDiscovery(device, packetSevice, masterService, 138 new LinkDiscovery(device, packetSevice, masterService,
138 providerService, useBDDP)); 139 providerService, useBDDP));
139 } else { 140 } else {
140 if (ld.isStopped()) { 141 if (ld.isStopped()) {
141 - log.debug("Device restarted ({}) {}", event.type(), device.id()); 142 + log.debug("Device restarted ({}) {}", event.type(), deviceId);
142 ld.start(); 143 ld.start();
143 } 144 }
144 } 145 }
...@@ -146,7 +147,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -146,7 +147,7 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
146 case PORT_ADDED: 147 case PORT_ADDED:
147 case PORT_UPDATED: 148 case PORT_UPDATED:
148 if (port.isEnabled()) { 149 if (port.isEnabled()) {
149 - ld = discoverers.get(device.id()); 150 + ld = discoverers.get(deviceId);
150 if (ld == null) { 151 if (ld == null) {
151 return; 152 return;
152 } 153 }
...@@ -156,47 +157,47 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider { ...@@ -156,47 +157,47 @@ public class LLDPLinkProvider extends AbstractProvider implements LinkProvider {
156 } 157 }
157 } else { 158 } else {
158 log.debug("Port down {}", port); 159 log.debug("Port down {}", port);
159 - ConnectPoint point = new ConnectPoint(device.id(), 160 + ConnectPoint point = new ConnectPoint(deviceId,
160 port.number()); 161 port.number());
161 providerService.linksVanished(point); 162 providerService.linksVanished(point);
162 } 163 }
163 break; 164 break;
164 case PORT_REMOVED: 165 case PORT_REMOVED:
165 log.debug("Port removed {}", port); 166 log.debug("Port removed {}", port);
166 - ConnectPoint point = new ConnectPoint(device.id(), 167 + ConnectPoint point = new ConnectPoint(deviceId,
167 port.number()); 168 port.number());
168 providerService.linksVanished(point); 169 providerService.linksVanished(point);
169 // TODO: Don't we need to removePort from ld? 170 // TODO: Don't we need to removePort from ld?
170 break; 171 break;
171 case DEVICE_REMOVED: 172 case DEVICE_REMOVED:
172 case DEVICE_SUSPENDED: 173 case DEVICE_SUSPENDED:
173 - log.debug("Device removed {}", device.id()); 174 + log.debug("Device removed {}", deviceId);
174 - ld = discoverers.get(device.id()); 175 + ld = discoverers.get(deviceId);
175 if (ld == null) { 176 if (ld == null) {
176 return; 177 return;
177 } 178 }
178 ld.stop(); 179 ld.stop();
179 - providerService.linksVanished(device.id()); 180 + providerService.linksVanished(deviceId);
180 break; 181 break;
181 case DEVICE_AVAILABILITY_CHANGED: 182 case DEVICE_AVAILABILITY_CHANGED:
182 - ld = discoverers.get(device.id()); 183 + ld = discoverers.get(deviceId);
183 if (ld == null) { 184 if (ld == null) {
184 return; 185 return;
185 } 186 }
186 - if (deviceService.isAvailable(device.id())) { 187 + if (deviceService.isAvailable(deviceId)) {
187 - log.debug("Device up {}", device.id()); 188 + log.debug("Device up {}", deviceId);
188 ld.start(); 189 ld.start();
189 } else { 190 } else {
190 - providerService.linksVanished(device.id()); 191 + providerService.linksVanished(deviceId);
191 - log.debug("Device down {}", device.id()); 192 + log.debug("Device down {}", deviceId);
192 ld.stop(); 193 ld.stop();
193 } 194 }
194 break; 195 break;
195 case DEVICE_MASTERSHIP_CHANGED: 196 case DEVICE_MASTERSHIP_CHANGED:
196 - if (!discoverers.containsKey(device.id())) { 197 + if (!discoverers.containsKey(deviceId)) {
197 // TODO: ideally, should never reach here 198 // TODO: ideally, should never reach here
198 - log.debug("Device mastership changed ({}) {}", event.type(), device.id()); 199 + log.debug("Device mastership changed ({}) {}", event.type(), deviceId);
199 - discoverers.put(device.id(), 200 + discoverers.put(deviceId,
200 new LinkDiscovery(device, packetSevice, masterService, 201 new LinkDiscovery(device, packetSevice, masterService,
201 providerService, useBDDP)); 202 providerService, useBDDP));
202 } 203 }
......