Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.devicemanager; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
| 5 | import java.util.Date; |
| 6 | import java.util.HashMap; |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 7 | import java.util.HashSet; |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 8 | import java.util.List; |
| 9 | import java.util.Map; |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 10 | import java.util.Set; |
| 11 | import java.util.concurrent.ConcurrentHashMap; |
| 12 | import java.util.concurrent.Executors; |
| 13 | import java.util.concurrent.ScheduledExecutorService; |
| 14 | import java.util.concurrent.TimeUnit; |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 15 | |
| 16 | import net.floodlightcontroller.core.FloodlightContext; |
| 17 | import net.floodlightcontroller.core.IFloodlightProviderService; |
| 18 | import net.floodlightcontroller.core.IOFMessageListener; |
| 19 | import net.floodlightcontroller.core.IOFSwitch; |
| 20 | import net.floodlightcontroller.core.IUpdate; |
| 21 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 22 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 23 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 24 | import net.floodlightcontroller.core.module.IFloodlightService; |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 25 | import net.floodlightcontroller.util.MACAddress; |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 26 | import net.onrc.onos.datagrid.IDatagridService; |
Jonathan Hart | 96892d1 | 2014-03-26 20:21:29 -0700 | [diff] [blame] | 27 | import net.onrc.onos.packet.ARP; |
| 28 | import net.onrc.onos.packet.DHCP; |
| 29 | import net.onrc.onos.packet.Ethernet; |
| 30 | import net.onrc.onos.packet.IPv4; |
| 31 | import net.onrc.onos.packet.UDP; |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 32 | |
| 33 | import org.openflow.protocol.OFMessage; |
| 34 | import org.openflow.protocol.OFPacketIn; |
| 35 | import org.openflow.protocol.OFType; |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 36 | import org.slf4j.Logger; |
| 37 | import org.slf4j.LoggerFactory; |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 38 | |
| 39 | public class OnosDeviceManager implements IFloodlightModule, IOFMessageListener, |
| 40 | IOnosDeviceService { |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 41 | protected final static Logger log = LoggerFactory.getLogger(OnosDeviceManager.class); |
| 42 | private static final int CLEANUP_SECOND = 60*60; |
| 43 | private static final int AGEING_MILLSEC = 60*60*1000; |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 44 | |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 45 | private IFloodlightProviderService floodlightProvider; |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 46 | private final static ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 47 | |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 48 | private IDatagridService datagrid; |
| 49 | private Map<Long, OnosDevice> mapDevice = new ConcurrentHashMap<Long, OnosDevice>(); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 50 | |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 51 | public enum OnosDeviceUpdateType { |
| 52 | ADD, DELETE, UPDATE; |
| 53 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 54 | |
Jonathan Hart | 18ad950 | 2013-12-15 18:28:00 -0800 | [diff] [blame] | 55 | private class OnosDeviceUpdate implements IUpdate { |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 56 | private OnosDevice device; |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 57 | private OnosDeviceUpdateType type; |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 58 | |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 59 | public OnosDeviceUpdate(OnosDevice device, OnosDeviceUpdateType type) { |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 60 | this.device = device; |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 61 | this.type = type; |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 62 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 63 | |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 64 | @Override |
| 65 | public void dispatch() { |
Pavlin Radoslavov | 5fe7188 | 2014-03-21 16:27:21 -0700 | [diff] [blame] | 66 | // TODO: Fix the code below after deviceStorage was removed |
| 67 | /* |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 68 | if(type == OnosDeviceUpdateType.ADD) { |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 69 | deviceStorage.addOnosDevice(device); |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 70 | } else if (type == OnosDeviceUpdateType.DELETE){ |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 71 | deviceStorage.deleteOnosDevice(device); |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 72 | } |
Pavlin Radoslavov | 5fe7188 | 2014-03-21 16:27:21 -0700 | [diff] [blame] | 73 | */ |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 74 | } |
| 75 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 76 | |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 77 | @Override |
| 78 | public String getName() { |
| 79 | return "onosdevicemanager"; |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public boolean isCallbackOrderingPrereq(OFType type, String name) { |
Jonathan Hart | 18ad950 | 2013-12-15 18:28:00 -0800 | [diff] [blame] | 84 | // We want link discovery to consume LLDP first otherwise we'll |
| 85 | // end up reading bad device info from LLDP packets |
| 86 | return type == OFType.PACKET_IN && "linkdiscovery".equals(name); |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public boolean isCallbackOrderingPostreq(OFType type, String name) { |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 91 | return type == OFType.PACKET_IN && |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 92 | ("proxyarpmanager".equals(name) || "onosforwarding".equals(name)); |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public Command receive(IOFSwitch sw, OFMessage msg, FloodlightContext cntx) { |
| 97 | if (msg.getType().equals(OFType.PACKET_IN)) { |
| 98 | OFPacketIn pi = (OFPacketIn) msg; |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 99 | |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 100 | Ethernet eth = IFloodlightProviderService.bcStore. |
| 101 | get(cntx, IFloodlightProviderService.CONTEXT_PI_PAYLOAD); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 102 | |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 103 | return processPacketIn(sw, pi, eth); |
| 104 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 105 | |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 106 | return Command.CONTINUE; |
| 107 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 108 | |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 109 | private Command processPacketIn(IOFSwitch sw, OFPacketIn pi, Ethernet eth) { |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 110 | long dpid =sw.getId(); |
| 111 | short portId = pi.getInPort(); |
| 112 | Long mac = eth.getSourceMAC().toLong(); |
| 113 | |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 114 | OnosDevice srcDevice = |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 115 | getSourceDeviceFromPacket(eth, dpid, portId); |
| 116 | |
| 117 | if (srcDevice == null){ |
| 118 | return Command.STOP; |
| 119 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 120 | |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 121 | //We check if it is the same device in datagrid to suppress the device update |
| 122 | OnosDevice exDev = null; |
| 123 | if((exDev = mapDevice.get(mac)) != null ){ |
| 124 | if(exDev.equals(srcDevice)) { |
| 125 | //There is the same existing device. Update only ActiveSince time. |
| 126 | exDev.setLastSeenTimestamp(new Date()); |
| 127 | if(log.isTraceEnabled()) { |
| 128 | log.debug("In the datagrid, there is the same device." |
| 129 | + "Only update last seen time. dpid {}, port {}, mac {}, ip {}, lastSeenTime {}", |
| 130 | dpid, portId, srcDevice.getMacAddress(), srcDevice.getIpv4Address(), srcDevice.getLastSeenTimestamp().getTime()); |
| 131 | } |
| 132 | return Command.CONTINUE; |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 133 | } else if (srcDevice.getIpv4Address() == null && |
| 134 | exDev.getSwitchDPID().equals(srcDevice.getSwitchDPID()) && |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 135 | exDev.getSwitchPort() == srcDevice.getSwitchPort() && |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 136 | exDev.getVlan().equals(srcDevice.getVlan())) { |
| 137 | //Device attachment point and mac address are the same |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 138 | //but the packet does not have an ip address. |
| 139 | exDev.setLastSeenTimestamp(new Date()); |
| 140 | if(log.isTraceEnabled()) { |
| 141 | log.debug("In the datagrid, there is the same device with no ip." |
| 142 | + "Keep ip and update last seen time. dpid {}, port {}, mac {}, ip {}, lastSeenTime {}", |
| 143 | dpid, portId, srcDevice.getMacAddress(), srcDevice.getIpv4Address(), srcDevice.getLastSeenTimestamp().getTime()); |
| 144 | } |
| 145 | return Command.CONTINUE; |
| 146 | } |
| 147 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 148 | |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 149 | //If the switch port we try to attach a new device already has a link, then stop adding device |
Pavlin Radoslavov | 1237e39 | 2014-03-20 16:24:06 -0700 | [diff] [blame] | 150 | // TODO: Fix/update this after we refactor the Device Discovery mechanism |
| 151 | /* |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 152 | Collection<TopologyElement> list = datagrid.getAllTopologyElements(); |
| 153 | for(TopologyElement elem: list) { |
| 154 | if(elem.getType() == Type.ELEMENT_LINK) { |
| 155 | if((elem.getFromPort() == portId && elem.getFromSwitch() == dpid) || |
| 156 | (elem.getToPort() == portId && elem.getToSwitch() == dpid)) { |
| 157 | if(log.isTraceEnabled()) { |
| 158 | log.debug("Stop adding OnosDevice {} due to there is a link to: dpid {} port {}", |
| 159 | srcDevice.getMacAddress(), dpid, portId); |
| 160 | } |
| 161 | return Command.CONTINUE; |
| 162 | } |
| 163 | } |
| 164 | } |
Pavlin Radoslavov | 1237e39 | 2014-03-20 16:24:06 -0700 | [diff] [blame] | 165 | */ |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 166 | |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 167 | addOnosDevice(mac, srcDevice); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 168 | |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 169 | if(log.isTraceEnabled()) { |
| 170 | log.debug("Add device info in the set. dpid {}, port {}, mac {}, ip {}, lastSeenTime {}", |
| 171 | dpid, portId, srcDevice.getMacAddress(), srcDevice.getIpv4Address(), srcDevice.getLastSeenTimestamp().getTime()); |
| 172 | } |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 173 | return Command.CONTINUE; |
| 174 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 175 | |
| 176 | //Thread to delete devices periodically. |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 177 | //Remove all devices from the map first and then finally delete devices from the DB. |
| 178 | private class CleanDevice implements Runnable { |
| 179 | @Override |
| 180 | public void run() { |
| 181 | log.debug("called CleanDevice"); |
| 182 | try{ |
| 183 | Set<OnosDevice> deleteSet = new HashSet<OnosDevice>(); |
| 184 | for (OnosDevice dev : mapDevice.values() ) { |
| 185 | long now = new Date().getTime(); |
| 186 | if((now - dev.getLastSeenTimestamp().getTime() > AGEING_MILLSEC)) { |
| 187 | if(log.isTraceEnabled()) { |
| 188 | log.debug("Remove device info in the datagrid. dpid {}, port {}, mac {}, ip {}, lastSeenTime {}, diff {}", |
| 189 | dev.getSwitchDPID(), dev.getSwitchPort(), dev.getMacAddress(), dev.getIpv4Address(), |
| 190 | dev.getLastSeenTimestamp().getTime(), now - dev.getLastSeenTimestamp().getTime()); |
| 191 | } |
| 192 | deleteSet.add(dev); |
| 193 | } |
| 194 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 195 | |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 196 | for(OnosDevice dev : deleteSet) { |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 197 | deleteOnosDevice(dev); |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 198 | } |
| 199 | } catch(Exception e) { |
| 200 | log.error("Error:", e); |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 205 | /** |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 206 | * Get IP address from packet if the packet is either an ARP |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 207 | * or a DHCP packet |
| 208 | * @param eth |
| 209 | * @param dlAddr |
| 210 | * @return |
| 211 | */ |
| 212 | private int getSrcNwAddr(Ethernet eth, long dlAddr) { |
| 213 | if (eth.getPayload() instanceof ARP) { |
| 214 | ARP arp = (ARP) eth.getPayload(); |
| 215 | if ((arp.getProtocolType() == ARP.PROTO_TYPE_IP) && |
| 216 | (Ethernet.toLong(arp.getSenderHardwareAddress()) == dlAddr)) { |
| 217 | return IPv4.toIPv4Address(arp.getSenderProtocolAddress()); |
| 218 | } |
| 219 | } else if (eth.getPayload() instanceof IPv4) { |
| 220 | IPv4 ipv4 = (IPv4) eth.getPayload(); |
| 221 | if (ipv4.getPayload() instanceof UDP) { |
| 222 | UDP udp = (UDP)ipv4.getPayload(); |
| 223 | if (udp.getPayload() instanceof DHCP) { |
| 224 | DHCP dhcp = (DHCP)udp.getPayload(); |
| 225 | if (dhcp.getOpCode() == DHCP.OPCODE_REPLY) { |
| 226 | return ipv4.getSourceAddress(); |
| 227 | } |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Parse an entity from an {@link Ethernet} packet. |
| 236 | * @param eth the packet to parse |
| 237 | * @param sw the switch on which the packet arrived |
| 238 | * @param pi the original packetin |
| 239 | * @return the entity from the packet |
| 240 | */ |
| 241 | private OnosDevice getSourceDeviceFromPacket(Ethernet eth, |
| 242 | long swdpid, |
| 243 | short port) { |
| 244 | byte[] dlAddrArr = eth.getSourceMACAddress(); |
| 245 | long dlAddr = Ethernet.toLong(dlAddrArr); |
| 246 | |
| 247 | // Ignore broadcast/multicast source |
| 248 | if ((dlAddrArr[0] & 0x1) != 0) |
| 249 | return null; |
| 250 | |
| 251 | short vlan = eth.getVlanID(); |
| 252 | int nwSrc = getSrcNwAddr(eth, dlAddr); |
| 253 | return new OnosDevice(MACAddress.valueOf(dlAddr), |
| 254 | ((vlan >= 0) ? vlan : null), |
| 255 | ((nwSrc != 0) ? nwSrc : null), |
| 256 | swdpid, |
| 257 | port, |
| 258 | new Date()); |
| 259 | } |
| 260 | |
| 261 | @Override |
| 262 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 263 | List<Class<? extends IFloodlightService>> services = |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 264 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 265 | services.add(IOnosDeviceService.class); |
| 266 | return services; |
| 267 | } |
| 268 | |
| 269 | @Override |
| 270 | public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() { |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 271 | Map<Class<? extends IFloodlightService>, IFloodlightService> impls = |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 272 | new HashMap<Class<? extends IFloodlightService>, IFloodlightService>(); |
| 273 | impls.put(IOnosDeviceService.class, this); |
| 274 | return impls; |
| 275 | } |
| 276 | |
| 277 | @Override |
| 278 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 279 | List<Class<? extends IFloodlightService>> dependencies = |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 280 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 281 | dependencies.add(IFloodlightProviderService.class); |
| 282 | return dependencies; |
| 283 | } |
| 284 | |
| 285 | @Override |
| 286 | public void init(FloodlightModuleContext context) |
| 287 | throws FloodlightModuleException { |
| 288 | floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 289 | executor.scheduleAtFixedRate(new CleanDevice(), 30 ,CLEANUP_SECOND, TimeUnit.SECONDS); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 290 | |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 291 | datagrid = context.getServiceImpl(IDatagridService.class); |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | @Override |
| 295 | public void startUp(FloodlightModuleContext context) { |
| 296 | floodlightProvider.addOFMessageListener(OFType.PACKET_IN, this); |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 297 | datagrid.registerMapDeviceEventHandler(new MapDevListener()); |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 298 | } |
| 299 | |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 300 | @Override |
| 301 | public void deleteOnosDevice(OnosDevice dev) { |
| 302 | datagrid.sendNotificationDeviceDeleted(dev); |
| 303 | floodlightProvider.publishUpdate(new OnosDeviceUpdate(dev, OnosDeviceUpdateType.DELETE)); |
| 304 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 305 | |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 306 | @Override |
| 307 | public void addOnosDevice(Long mac, OnosDevice dev) { |
| 308 | datagrid.sendNotificationDeviceAdded(mac, dev); |
| 309 | floodlightProvider.publishUpdate(new OnosDeviceUpdate(dev, OnosDeviceUpdateType.ADD)); |
| 310 | } |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 311 | |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 312 | //This is listener for datagrid mapDevice change. |
| 313 | class MapDevListener implements IDeviceEventHandler { |
| 314 | |
| 315 | @Override |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 316 | public void addDeviceEvent(Long mac, OnosDevice dev) { |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 317 | mapDevice.put(mac, dev); |
| 318 | log.debug("addDeviceMap: device mac {}", mac); |
| 319 | } |
| 320 | |
| 321 | @Override |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 322 | public void deleteDeviceEvent(Long mac, OnosDevice dev) { |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 323 | mapDevice.remove(mac); |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 324 | log.debug("deleteDeviceMap: device mac {}", mac); |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | @Override |
Yuta HIGUCHI | e7eac18 | 2014-03-19 19:18:30 -0700 | [diff] [blame] | 328 | public void updateDeviceEvent(Long mac, OnosDevice dev) { |
TeruU | 80ce506 | 2014-03-03 17:16:13 -0800 | [diff] [blame] | 329 | mapDevice.put(mac, dev); |
| 330 | log.debug("updateDeviceMap: device mac {}", mac); |
| 331 | } |
| 332 | } |
Jonathan Hart | d857ad6 | 2013-12-14 18:08:17 -0800 | [diff] [blame] | 333 | } |