Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 1 | package net.onrc.onos.ofcontroller.floodlightlistener; |
| 2 | |
| 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
| 5 | import java.util.Map; |
| 6 | |
| 7 | import net.floodlightcontroller.core.IFloodlightProviderService; |
| 8 | import net.floodlightcontroller.core.IOFSwitch; |
| 9 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 10 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 11 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 12 | import net.floodlightcontroller.core.module.IFloodlightService; |
| 13 | import net.onrc.onos.datagrid.IDatagridService; |
| 14 | import net.onrc.onos.ofcontroller.core.IOFSwitchPortListener; |
| 15 | import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryListener; |
| 16 | import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryService; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 17 | import net.onrc.onos.ofcontroller.networkgraph.INetworkGraphService; |
Jonathan Hart | 22eb988 | 2014-02-11 15:52:59 -0800 | [diff] [blame] | 18 | import net.onrc.onos.ofcontroller.networkgraph.LinkEvent; |
| 19 | import net.onrc.onos.ofcontroller.networkgraph.NetworkGraphDiscoveryInterface; |
| 20 | import net.onrc.onos.ofcontroller.networkgraph.SwitchEvent; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 21 | import net.onrc.onos.registry.controller.IControllerRegistryService; |
| 22 | |
| 23 | import org.openflow.protocol.OFPhysicalPort; |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 24 | import org.slf4j.Logger; |
| 25 | import org.slf4j.LoggerFactory; |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 26 | |
| 27 | /* |
| 28 | * I've created a copy of the NetworkGraphPublisher so I can integrate |
| 29 | * the new API with ONOS while still having the old NetworkGraphPublisher |
| 30 | * to reference. I've renamed to RCNetworkGraphPublisher. |
| 31 | * TODO Remove old NetworkGraphPublisher once the integration of the new |
| 32 | * API is complete. |
| 33 | * For now, we just write to the database and don't worry about sending |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 34 | * notifications. |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 35 | * TODO Send notification after each database write |
| 36 | */ |
| 37 | public class RCNetworkGraphPublisher implements /*IOFSwitchListener,*/ |
| 38 | IOFSwitchPortListener, |
| 39 | ILinkDiscoveryListener, |
| 40 | IFloodlightModule { |
Jonathan Hart | 4701671 | 2014-02-07 12:41:35 -0800 | [diff] [blame] | 41 | private static final Logger log = LoggerFactory.getLogger(RCNetworkGraphPublisher.class); |
Yuta HIGUCHI | cb95198 | 2014-02-11 13:31:44 -0800 | [diff] [blame] | 42 | |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 43 | private IFloodlightProviderService floodlightProvider; |
| 44 | private ILinkDiscoveryService linkDiscovery; |
| 45 | private IControllerRegistryService registryService; |
| 46 | private IDatagridService datagridService; |
| 47 | private INetworkGraphService networkGraphService; |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 48 | |
Jonathan Hart | 22eb988 | 2014-02-11 15:52:59 -0800 | [diff] [blame] | 49 | private NetworkGraphDiscoveryInterface networkGraphDiscoveryInterface; |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 50 | |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 51 | |
| 52 | @Override |
| 53 | public void linkDiscoveryUpdate(LDUpdate update) { |
Jonathan Hart | 22eb988 | 2014-02-11 15:52:59 -0800 | [diff] [blame] | 54 | LinkEvent linkEvent = new LinkEvent(update.getSrc(), |
| 55 | (long)update.getSrcPort(), update.getDst(), |
| 56 | (long)update.getDstPort()); |
| 57 | |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 58 | switch (update.getOperation()) { |
| 59 | case LINK_ADDED: |
Jonathan Hart | 22eb988 | 2014-02-11 15:52:59 -0800 | [diff] [blame] | 60 | networkGraphDiscoveryInterface.putLinkEvent(linkEvent); |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 61 | /* |
| 62 | TopologyElement topologyElement = |
| 63 | new TopologyElement(update.getSrc(), |
| 64 | update.getSrcPort(), |
| 65 | update.getDst(), |
| 66 | update.getDstPort()); |
| 67 | datagridService.notificationSendTopologyElementAdded(topologyElement); |
| 68 | */ |
| 69 | break; |
| 70 | case LINK_UPDATED: |
| 71 | // I don't know what a LINK_UPDATED event is. |
| 72 | // We never use it. |
| 73 | break; |
| 74 | case LINK_REMOVED: |
Jonathan Hart | 22eb988 | 2014-02-11 15:52:59 -0800 | [diff] [blame] | 75 | networkGraphDiscoveryInterface.removeLinkEvent(linkEvent); |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 76 | /* |
| 77 | TopologyElement topologyElement = |
| 78 | new TopologyElement(update.getSrc(), |
| 79 | update.getSrcPort(), |
| 80 | update.getDst(), |
| 81 | update.getDstPort()); |
| 82 | datagridService.notificationSendTopologyElementRemoved(topologyElement); |
| 83 | */ |
| 84 | break; |
| 85 | default: |
| 86 | break; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public void switchPortAdded(Long switchId, OFPhysicalPort port) { |
| 92 | // TODO Auto-generated method stub |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 93 | |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public void switchPortRemoved(Long switchId, OFPhysicalPort port) { |
| 98 | // TODO Auto-generated method stub |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 99 | |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public void addedSwitch(IOFSwitch sw) { |
| 104 | // TODO Not very robust |
| 105 | if (!registryService.hasControl(sw.getId())) { |
| 106 | return; |
| 107 | } |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 108 | |
Jonathan Hart | 22eb988 | 2014-02-11 15:52:59 -0800 | [diff] [blame] | 109 | SwitchEvent switchEvent = new SwitchEvent(sw.getId()); |
| 110 | networkGraphDiscoveryInterface.putSwitchEvent(switchEvent); |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 111 | |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 112 | /* |
| 113 | // TODO publish ADD_SWITCH event here |
| 114 | TopologyElement topologyElement = |
| 115 | new TopologyElement(sw.getId()); |
| 116 | datagridService.notificationSendTopologyElementAdded(topologyElement); |
| 117 | |
| 118 | // Publish: add the ports |
| 119 | // TODO: Add only ports that are UP? |
| 120 | for (OFPhysicalPort port : sw.getPorts()) { |
| 121 | TopologyElement topologyElementPort = |
| 122 | new TopologyElement(sw.getId(), port.getPortNumber()); |
| 123 | datagridService.notificationSendTopologyElementAdded(topologyElementPort); |
| 124 | |
| 125 | // Allow links to be discovered on this port now that it's |
| 126 | // in the database |
| 127 | linkDiscovery.RemoveFromSuppressLLDPs(sw.getId(), port.getPortNumber()); |
| 128 | } |
| 129 | |
| 130 | // Add all links that might be connected already |
| 131 | List<Link> links = linkStore.getLinks(HexString.toHexString(sw.getId())); |
| 132 | // Add all reverse links as well |
| 133 | List<Link> reverseLinks = linkStore.getReverseLinks(HexString.toHexString(sw.getId())); |
| 134 | links.addAll(reverseLinks); |
| 135 | |
| 136 | // Publish: add the links |
| 137 | for (Link link : links) { |
| 138 | TopologyElement topologyElementLink = |
| 139 | new TopologyElement(link.getSrc(), |
| 140 | link.getSrcPort(), |
| 141 | link.getDst(), |
| 142 | link.getDstPort()); |
| 143 | datagridService.notificationSendTopologyElementAdded(topologyElementLink); |
| 144 | */ |
| 145 | } |
| 146 | |
| 147 | @Override |
| 148 | public void removedSwitch(IOFSwitch sw) { |
Jonathan Hart | 22eb988 | 2014-02-11 15:52:59 -0800 | [diff] [blame] | 149 | // TODO move to cleanup thread |
| 150 | SwitchEvent switchEvent = new SwitchEvent(sw.getId()); |
| 151 | networkGraphDiscoveryInterface.removeSwitchEvent(switchEvent); |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public void switchPortChanged(Long switchId) { |
| 156 | // TODO Auto-generated method stub |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 157 | |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | @Override |
| 161 | public String getName() { |
| 162 | // TODO Auto-generated method stub |
| 163 | return null; |
| 164 | } |
| 165 | |
| 166 | /* ***************** |
| 167 | * IFloodlightModule |
| 168 | * *****************/ |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 169 | |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 170 | @Override |
| 171 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 172 | return null; |
| 173 | } |
| 174 | |
| 175 | @Override |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 176 | public Map<Class<? extends IFloodlightService>, IFloodlightService> |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 177 | getServiceImpls() { |
| 178 | return null; |
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
| 183 | Collection<Class<? extends IFloodlightService>> l = |
| 184 | new ArrayList<Class<? extends IFloodlightService>>(); |
| 185 | l.add(IFloodlightProviderService.class); |
| 186 | l.add(ILinkDiscoveryService.class); |
| 187 | l.add(IControllerRegistryService.class); |
| 188 | l.add(IDatagridService.class); |
| 189 | l.add(INetworkGraphService.class); |
| 190 | return l; |
| 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public void init(FloodlightModuleContext context) |
| 195 | throws FloodlightModuleException { |
| 196 | floodlightProvider = context.getServiceImpl(IFloodlightProviderService.class); |
| 197 | linkDiscovery = context.getServiceImpl(ILinkDiscoveryService.class); |
| 198 | registryService = context.getServiceImpl(IControllerRegistryService.class); |
| 199 | datagridService = context.getServiceImpl(IDatagridService.class); |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 200 | |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 201 | networkGraphService = context.getServiceImpl(INetworkGraphService.class); |
| 202 | } |
| 203 | |
| 204 | @Override |
| 205 | public void startUp(FloodlightModuleContext context) { |
| 206 | // TODO enable cleanup thread |
| 207 | floodlightProvider.addOFSwitchListener(this); |
| 208 | linkDiscovery.addListener(this); |
Toshio Koide | 2f570c1 | 2014-02-06 16:55:32 -0800 | [diff] [blame] | 209 | |
Jonathan Hart | 22eb988 | 2014-02-11 15:52:59 -0800 | [diff] [blame] | 210 | networkGraphDiscoveryInterface = networkGraphService.getNetworkGraphDiscoveryInterface(); |
Jonathan Hart | 4b5bbb5 | 2014-02-06 10:09:31 -0800 | [diff] [blame] | 211 | } |
| 212 | } |