blob: 156ee1a3dba555f4c33f3c6d8c91594be8325b8b [file] [log] [blame]
Jonathan Hart4b5bbb52014-02-06 10:09:31 -08001package net.onrc.onos.ofcontroller.floodlightlistener;
2
3import java.util.ArrayList;
4import java.util.Collection;
5import java.util.Map;
6
7import net.floodlightcontroller.core.IFloodlightProviderService;
8import net.floodlightcontroller.core.IOFSwitch;
9import net.floodlightcontroller.core.module.FloodlightModuleContext;
10import net.floodlightcontroller.core.module.FloodlightModuleException;
11import net.floodlightcontroller.core.module.IFloodlightModule;
12import net.floodlightcontroller.core.module.IFloodlightService;
13import net.onrc.onos.datagrid.IDatagridService;
14import net.onrc.onos.ofcontroller.core.IOFSwitchPortListener;
15import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryListener;
16import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryService;
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080017import net.onrc.onos.ofcontroller.networkgraph.INetworkGraphService;
Jonathan Hart22eb9882014-02-11 15:52:59 -080018import net.onrc.onos.ofcontroller.networkgraph.LinkEvent;
19import net.onrc.onos.ofcontroller.networkgraph.NetworkGraphDiscoveryInterface;
20import net.onrc.onos.ofcontroller.networkgraph.SwitchEvent;
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080021import net.onrc.onos.registry.controller.IControllerRegistryService;
22
23import org.openflow.protocol.OFPhysicalPort;
Toshio Koide2f570c12014-02-06 16:55:32 -080024import org.slf4j.Logger;
25import org.slf4j.LoggerFactory;
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080026
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 Koide2f570c12014-02-06 16:55:32 -080034 * notifications.
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080035 * TODO Send notification after each database write
36 */
37public class RCNetworkGraphPublisher implements /*IOFSwitchListener,*/
38 IOFSwitchPortListener,
39 ILinkDiscoveryListener,
40 IFloodlightModule {
Jonathan Hart47016712014-02-07 12:41:35 -080041 private static final Logger log = LoggerFactory.getLogger(RCNetworkGraphPublisher.class);
Yuta HIGUCHIcb951982014-02-11 13:31:44 -080042
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080043 private IFloodlightProviderService floodlightProvider;
44 private ILinkDiscoveryService linkDiscovery;
45 private IControllerRegistryService registryService;
46 private IDatagridService datagridService;
47 private INetworkGraphService networkGraphService;
Toshio Koide2f570c12014-02-06 16:55:32 -080048
Jonathan Hart22eb9882014-02-11 15:52:59 -080049 private NetworkGraphDiscoveryInterface networkGraphDiscoveryInterface;
Toshio Koide2f570c12014-02-06 16:55:32 -080050
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080051
52 @Override
53 public void linkDiscoveryUpdate(LDUpdate update) {
Jonathan Hart22eb9882014-02-11 15:52:59 -080054 LinkEvent linkEvent = new LinkEvent(update.getSrc(),
55 (long)update.getSrcPort(), update.getDst(),
56 (long)update.getDstPort());
57
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080058 switch (update.getOperation()) {
59 case LINK_ADDED:
Jonathan Hart22eb9882014-02-11 15:52:59 -080060 networkGraphDiscoveryInterface.putLinkEvent(linkEvent);
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080061 /*
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 Hart22eb9882014-02-11 15:52:59 -080075 networkGraphDiscoveryInterface.removeLinkEvent(linkEvent);
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080076 /*
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 Koide2f570c12014-02-06 16:55:32 -080093
Jonathan Hart4b5bbb52014-02-06 10:09:31 -080094 }
95
96 @Override
97 public void switchPortRemoved(Long switchId, OFPhysicalPort port) {
98 // TODO Auto-generated method stub
Toshio Koide2f570c12014-02-06 16:55:32 -080099
Jonathan Hart4b5bbb52014-02-06 10:09:31 -0800100 }
101
102 @Override
103 public void addedSwitch(IOFSwitch sw) {
104 // TODO Not very robust
105 if (!registryService.hasControl(sw.getId())) {
106 return;
107 }
Toshio Koide2f570c12014-02-06 16:55:32 -0800108
Jonathan Hart22eb9882014-02-11 15:52:59 -0800109 SwitchEvent switchEvent = new SwitchEvent(sw.getId());
110 networkGraphDiscoveryInterface.putSwitchEvent(switchEvent);
Toshio Koide2f570c12014-02-06 16:55:32 -0800111
Jonathan Hart4b5bbb52014-02-06 10:09:31 -0800112 /*
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 Hart22eb9882014-02-11 15:52:59 -0800149 // TODO move to cleanup thread
150 SwitchEvent switchEvent = new SwitchEvent(sw.getId());
151 networkGraphDiscoveryInterface.removeSwitchEvent(switchEvent);
Jonathan Hart4b5bbb52014-02-06 10:09:31 -0800152 }
153
154 @Override
155 public void switchPortChanged(Long switchId) {
156 // TODO Auto-generated method stub
Toshio Koide2f570c12014-02-06 16:55:32 -0800157
Jonathan Hart4b5bbb52014-02-06 10:09:31 -0800158 }
159
160 @Override
161 public String getName() {
162 // TODO Auto-generated method stub
163 return null;
164 }
165
166 /* *****************
167 * IFloodlightModule
168 * *****************/
Toshio Koide2f570c12014-02-06 16:55:32 -0800169
Jonathan Hart4b5bbb52014-02-06 10:09:31 -0800170 @Override
171 public Collection<Class<? extends IFloodlightService>> getModuleServices() {
172 return null;
173 }
174
175 @Override
Toshio Koide2f570c12014-02-06 16:55:32 -0800176 public Map<Class<? extends IFloodlightService>, IFloodlightService>
Jonathan Hart4b5bbb52014-02-06 10:09:31 -0800177 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 Koide2f570c12014-02-06 16:55:32 -0800200
Jonathan Hart4b5bbb52014-02-06 10:09:31 -0800201 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 Koide2f570c12014-02-06 16:55:32 -0800209
Jonathan Hart22eb9882014-02-11 15:52:59 -0800210 networkGraphDiscoveryInterface = networkGraphService.getNetworkGraphDiscoveryInterface();
Jonathan Hart4b5bbb52014-02-06 10:09:31 -0800211 }
212}