Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.matchaction; |
| 2 | |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 3 | import java.util.ArrayList; |
| 4 | import java.util.Collection; |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 5 | import java.util.EventListener; |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 6 | import java.util.HashMap; |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 7 | import java.util.List; |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 8 | import java.util.Map; |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 9 | import java.util.Set; |
Toshio Koide | 77ec998 | 2014-08-27 16:57:43 -0700 | [diff] [blame] | 10 | |
Ray Milkey | 626a2b1 | 2014-09-02 11:19:06 -0700 | [diff] [blame] | 11 | import net.floodlightcontroller.core.IFloodlightProviderService; |
| 12 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 13 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 14 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 15 | import net.floodlightcontroller.core.module.IFloodlightService; |
Jonathan Hart | 763fb7e | 2014-09-02 15:06:46 -0700 | [diff] [blame] | 16 | import net.floodlightcontroller.restserver.IRestApiService; |
Ray Milkey | 626a2b1 | 2014-09-02 11:19:06 -0700 | [diff] [blame] | 17 | import net.onrc.onos.api.flowmanager.ConflictDetectionPolicy; |
| 18 | import net.onrc.onos.core.datagrid.IDatagridService; |
| 19 | import net.onrc.onos.core.flowprogrammer.IFlowPusherService; |
Jonathan Hart | 763fb7e | 2014-09-02 15:06:46 -0700 | [diff] [blame] | 20 | import net.onrc.onos.core.matchaction.web.MatchActionWebRoutable; |
Ray Milkey | 626a2b1 | 2014-09-02 11:19:06 -0700 | [diff] [blame] | 21 | import net.onrc.onos.core.registry.IControllerRegistryService; |
| 22 | import net.onrc.onos.core.util.IdGenerator; |
| 23 | |
| 24 | import org.slf4j.Logger; |
| 25 | import org.slf4j.LoggerFactory; |
| 26 | |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 27 | /** |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 28 | * Floodlight module for Match Action service. |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 29 | */ |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 30 | |
| 31 | public class MatchActionModule implements MatchActionFloodlightService, IFloodlightModule { |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 32 | |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 33 | private static final Logger log = LoggerFactory |
| 34 | .getLogger(MatchActionModule.class); |
| 35 | private MatchActionComponent matchActionComponent; |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 36 | |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 37 | @Override |
| 38 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 39 | List<Class<? extends IFloodlightService>> services = new ArrayList<>(); |
| 40 | log.info("get module services"); |
| 41 | services.add(MatchActionFloodlightService.class); |
| 42 | return services; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() { |
| 47 | Map<Class<? extends IFloodlightService>, IFloodlightService> impls = |
| 48 | new HashMap<>(); |
| 49 | impls.put(MatchActionFloodlightService.class, this); |
| 50 | return impls; |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
| 55 | List<Class<? extends IFloodlightService>> dependencies = new ArrayList<>(); |
| 56 | dependencies.add(IDatagridService.class); |
| 57 | dependencies.add(IFlowPusherService.class); |
| 58 | dependencies.add(IFloodlightProviderService.class); |
Ray Milkey | 626a2b1 | 2014-09-02 11:19:06 -0700 | [diff] [blame] | 59 | dependencies.add(IControllerRegistryService.class); |
Jonathan Hart | 763fb7e | 2014-09-02 15:06:46 -0700 | [diff] [blame] | 60 | dependencies.add(IRestApiService.class); |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 61 | return dependencies; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public void init(FloodlightModuleContext context) throws FloodlightModuleException { |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 66 | final IDatagridService datagrid = context.getServiceImpl(IDatagridService.class); |
| 67 | final IFlowPusherService pusher = context.getServiceImpl(IFlowPusherService.class); |
| 68 | final IFloodlightProviderService provider = context.getServiceImpl(IFloodlightProviderService.class); |
Ray Milkey | 626a2b1 | 2014-09-02 11:19:06 -0700 | [diff] [blame] | 69 | final IControllerRegistryService registry = context.getServiceImpl(IControllerRegistryService.class); |
Jonathan Hart | 763fb7e | 2014-09-02 15:06:46 -0700 | [diff] [blame] | 70 | final IRestApiService restApi = context.getServiceImpl(IRestApiService.class); |
| 71 | |
| 72 | restApi.addRestletRoutable(new MatchActionWebRoutable()); |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 73 | |
Ray Milkey | 626a2b1 | 2014-09-02 11:19:06 -0700 | [diff] [blame] | 74 | matchActionComponent = new MatchActionComponent(datagrid, pusher, provider, registry); |
Brian O'Connor | 7e2d914 | 2014-09-02 17:24:27 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public void startUp(FloodlightModuleContext context) throws FloodlightModuleException { |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 79 | matchActionComponent.start(); |
Ray Milkey | c127a5a | 2014-08-20 11:22:12 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 82 | @Override |
| 83 | public boolean addMatchAction(MatchAction matchAction) { |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 84 | return matchActionComponent.addMatchAction(matchAction); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | @Override |
Brian O'Connor | dee2e6b | 2014-08-12 11:34:51 -0700 | [diff] [blame] | 88 | public Set<MatchAction> getMatchActions() { |
Brian O'Connor | 7e2d914 | 2014-09-02 17:24:27 -0700 | [diff] [blame] | 89 | return matchActionComponent.getMatchActions(); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | @Override |
Ray Milkey | 18b44ac | 2014-08-22 08:29:47 -0700 | [diff] [blame] | 93 | public boolean executeOperations(MatchActionOperations operations) { |
Brian O'Connor | 7e2d914 | 2014-09-02 17:24:27 -0700 | [diff] [blame] | 94 | matchActionComponent.installMatchActionOperations(operations); |
| 95 | return false; // TODO define return value semantics |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public void setConflictDetectionPolicy(ConflictDetectionPolicy policy) { |
Ray Milkey | a313cde | 2014-09-05 09:02:52 -0700 | [diff] [blame] | 100 | throw new UnsupportedOperationException("conflict detection not implemented yet"); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public ConflictDetectionPolicy getConflictDetectionPolicy() { |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 105 | return null; |
| 106 | } |
| 107 | |
| 108 | @Override |
Sho SHIMIZU | 7cd8a42 | 2014-08-27 16:05:21 -0700 | [diff] [blame] | 109 | public IdGenerator<MatchActionId> getMatchActionIdGenerator() { |
Ray Milkey | 626a2b1 | 2014-09-02 11:19:06 -0700 | [diff] [blame] | 110 | return matchActionComponent.getMatchActionIdGenerator(); |
Toshio Koide | 77ec998 | 2014-08-27 16:57:43 -0700 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | @Override |
Sho SHIMIZU | 7cd8a42 | 2014-08-27 16:05:21 -0700 | [diff] [blame] | 114 | public IdGenerator<MatchActionOperationsId> getMatchActionOperationsIdGenerator() { |
Ray Milkey | 626a2b1 | 2014-09-02 11:19:06 -0700 | [diff] [blame] | 115 | return matchActionComponent.getMatchActionOperationsIdGenerator(); |
Toshio Koide | 77ec998 | 2014-08-27 16:57:43 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | @Override |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 119 | public void addEventListener(EventListener listener) { |
Brian O'Connor | ab3e9e6 | 2014-09-09 23:45:55 -0700 | [diff] [blame] | 120 | // TODO |
| 121 | log.warn("Could not add MatchAction EventListener: {}", listener); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public void removeEventListener(EventListener listener) { |
Brian O'Connor | ab3e9e6 | 2014-09-09 23:45:55 -0700 | [diff] [blame] | 126 | // TODO |
| 127 | log.warn("Could not remove MatchAction EventListener: {}", listener); |
Toshio Koide | a03915e | 2014-07-01 18:39:52 -0700 | [diff] [blame] | 128 | } |
| 129 | } |