Sho SHIMIZU | 4744151 | 2014-08-26 10:14:22 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.newintent; |
| 2 | |
Jonathan Hart | 68e8dd6 | 2014-08-26 18:06:23 -0700 | [diff] [blame] | 3 | import java.util.ArrayList; |
| 4 | import java.util.Arrays; |
| 5 | import java.util.Collection; |
| 6 | import java.util.HashMap; |
| 7 | import java.util.Map; |
| 8 | import java.util.Set; |
| 9 | |
Sho SHIMIZU | 4744151 | 2014-08-26 10:14:22 -0700 | [diff] [blame] | 10 | import net.floodlightcontroller.core.module.FloodlightModuleContext; |
| 11 | import net.floodlightcontroller.core.module.FloodlightModuleException; |
| 12 | import net.floodlightcontroller.core.module.IFloodlightModule; |
| 13 | import net.floodlightcontroller.core.module.IFloodlightService; |
Jonathan Hart | 68e8dd6 | 2014-08-26 18:06:23 -0700 | [diff] [blame] | 14 | import net.floodlightcontroller.restserver.IRestApiService; |
Sho SHIMIZU | 7cd8a42 | 2014-08-27 16:05:21 -0700 | [diff] [blame] | 15 | import net.onrc.onos.api.flowmanager.FlowId; |
Sho SHIMIZU | 4744151 | 2014-08-26 10:14:22 -0700 | [diff] [blame] | 16 | import net.onrc.onos.api.flowmanager.FlowManagerFloodlightService; |
| 17 | import net.onrc.onos.api.flowmanager.FlowManagerService; |
| 18 | import net.onrc.onos.api.newintent.InstallableIntent; |
| 19 | import net.onrc.onos.api.newintent.Intent; |
| 20 | import net.onrc.onos.api.newintent.IntentCompiler; |
| 21 | import net.onrc.onos.api.newintent.IntentEventListener; |
| 22 | import net.onrc.onos.api.newintent.IntentFloodlightService; |
| 23 | import net.onrc.onos.api.newintent.IntentId; |
Sho SHIMIZU | 4744151 | 2014-08-26 10:14:22 -0700 | [diff] [blame] | 24 | import net.onrc.onos.api.newintent.IntentInstaller; |
| 25 | import net.onrc.onos.api.newintent.IntentManager; |
| 26 | import net.onrc.onos.api.newintent.IntentOperations; |
| 27 | import net.onrc.onos.api.newintent.IntentState; |
| 28 | import net.onrc.onos.api.newintent.MultiPointToSinglePointIntent; |
| 29 | import net.onrc.onos.api.newintent.PathIntent; |
| 30 | import net.onrc.onos.api.newintent.PointToPointIntent; |
| 31 | import net.onrc.onos.core.datagrid.ISharedCollectionsService; |
Jonathan Hart | 68e8dd6 | 2014-08-26 18:06:23 -0700 | [diff] [blame] | 32 | import net.onrc.onos.core.newintent.web.IntentWebRoutable; |
Sho SHIMIZU | 4744151 | 2014-08-26 10:14:22 -0700 | [diff] [blame] | 33 | import net.onrc.onos.core.registry.IControllerRegistryService; |
| 34 | import net.onrc.onos.core.topology.ITopologyService; |
| 35 | import net.onrc.onos.core.util.IdBlockAllocator; |
Sho SHIMIZU | 7cd8a42 | 2014-08-27 16:05:21 -0700 | [diff] [blame] | 36 | import net.onrc.onos.core.util.IdGenerator; |
Sho SHIMIZU | 4744151 | 2014-08-26 10:14:22 -0700 | [diff] [blame] | 37 | |
Sho SHIMIZU | 4744151 | 2014-08-26 10:14:22 -0700 | [diff] [blame] | 38 | /** |
| 39 | * A Floodlight module for Intent Service. |
| 40 | */ |
| 41 | public class IntentFloodlightModule implements IntentFloodlightService, IFloodlightModule { |
| 42 | private IntentManager intentManager; |
| 43 | |
| 44 | @Override |
| 45 | public Collection<Class<? extends IFloodlightService>> getModuleServices() { |
| 46 | Collection<Class<? extends IFloodlightService>> services = new ArrayList<>(); |
| 47 | services.add(IntentFloodlightService.class); |
| 48 | return services; |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() { |
| 53 | Map<Class<? extends IFloodlightService>, IFloodlightService> impls = new HashMap<>(); |
Jonathan Hart | 68e8dd6 | 2014-08-26 18:06:23 -0700 | [diff] [blame] | 54 | impls.put(IntentFloodlightService.class, this); |
Sho SHIMIZU | 4744151 | 2014-08-26 10:14:22 -0700 | [diff] [blame] | 55 | return impls; |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public Collection<Class<? extends IFloodlightService>> getModuleDependencies() { |
| 60 | return Arrays.asList( |
| 61 | ISharedCollectionsService.class, |
| 62 | IControllerRegistryService.class, |
| 63 | FlowManagerFloodlightService.class, |
| 64 | ITopologyService.class |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public void init(FloodlightModuleContext context) throws FloodlightModuleException { |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public void startUp(FloodlightModuleContext context) throws FloodlightModuleException { |
| 74 | intentManager = |
| 75 | new IntentManagerRuntime( |
| 76 | context.getServiceImpl(ISharedCollectionsService.class) |
| 77 | ); |
| 78 | |
| 79 | IdBlockAllocator idBlockAllocator = |
| 80 | context.getServiceImpl(IControllerRegistryService.class); |
Sho SHIMIZU | 7cd8a42 | 2014-08-27 16:05:21 -0700 | [diff] [blame] | 81 | IdGenerator<IntentId> intentIdGenerator = |
Sho SHIMIZU | 4744151 | 2014-08-26 10:14:22 -0700 | [diff] [blame] | 82 | new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator); |
| 83 | FlowManagerService flowManagerService = |
| 84 | context.getServiceImpl(FlowManagerFloodlightService.class); |
Sho SHIMIZU | 7cd8a42 | 2014-08-27 16:05:21 -0700 | [diff] [blame] | 85 | IdGenerator<FlowId> flowIdGenerator = |
Sho SHIMIZU | 4744151 | 2014-08-26 10:14:22 -0700 | [diff] [blame] | 86 | flowManagerService.getFlowIdGenerator(); |
| 87 | |
| 88 | ITopologyService topologyService = |
| 89 | context.getServiceImpl(ITopologyService.class); |
| 90 | |
| 91 | registerDefaultCompilers(intentIdGenerator, flowIdGenerator, topologyService); |
| 92 | registerDefaultInstallers(flowManagerService); |
Jonathan Hart | 68e8dd6 | 2014-08-26 18:06:23 -0700 | [diff] [blame] | 93 | |
| 94 | IRestApiService restApi = context.getServiceImpl(IRestApiService.class); |
| 95 | restApi.addRestletRoutable(new IntentWebRoutable()); |
Sho SHIMIZU | 4744151 | 2014-08-26 10:14:22 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Sho SHIMIZU | 7cd8a42 | 2014-08-27 16:05:21 -0700 | [diff] [blame] | 98 | private void registerDefaultCompilers(IdGenerator<IntentId> intentIdGenerator, |
| 99 | IdGenerator<FlowId> flowIdGenerator, |
Sho SHIMIZU | 4744151 | 2014-08-26 10:14:22 -0700 | [diff] [blame] | 100 | ITopologyService topologyService) { |
| 101 | intentManager.registerCompiler(PointToPointIntent.class, |
| 102 | new PointToPointIntentCompiler(intentIdGenerator, |
| 103 | flowIdGenerator, topologyService)); |
| 104 | |
| 105 | intentManager.registerCompiler(PathIntent.class, |
| 106 | new PathIntentCompiler(intentIdGenerator, flowIdGenerator)); |
| 107 | |
| 108 | intentManager.registerCompiler(MultiPointToSinglePointIntent.class, |
| 109 | new MultiPointToSinglePointIntentCompiler(intentIdGenerator, |
| 110 | flowIdGenerator, topologyService)); |
| 111 | } |
| 112 | |
| 113 | private void registerDefaultInstallers(FlowManagerService flowManagerService) { |
| 114 | intentManager.registerInstaller(PathFlowIntent.class, |
| 115 | new PathFlowIntentInstaller(flowManagerService)); |
| 116 | intentManager.registerInstaller(SingleDstTreeFlowIntent.class, |
| 117 | new SingleDstTreeFlowIntentInstaller(flowManagerService)); |
| 118 | intentManager.registerInstaller(SingleSrcTreeFlowIntent.class, |
| 119 | new SingleSrcTreeFlowIntentInstaller(flowManagerService)); |
| 120 | } |
| 121 | |
| 122 | /* |
| 123 | All methods defined in IntentFloodlightService are delegated to IntentManager |
| 124 | implementation this class has. It helps to reduce the code size of this class |
| 125 | (IntentModule) and to make IntentManager implementation more testable. |
| 126 | */ |
| 127 | // All methods below are methods defined in IntentFloodlightService. |
| 128 | @Override |
| 129 | public void submit(Intent intent) { |
| 130 | intentManager.submit(intent); |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public void withdraw(Intent intent) { |
| 135 | intentManager.withdraw(intent); |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public void execute(IntentOperations operations) { |
| 140 | intentManager.execute(operations); |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | public Set<Intent> getIntents() { |
| 145 | return intentManager.getIntents(); |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public Intent getIntent(IntentId id) { |
| 150 | return intentManager.getIntent(id); |
| 151 | } |
| 152 | |
| 153 | @Override |
| 154 | public IntentState getIntentState(IntentId id) { |
| 155 | return intentManager.getIntentState(id); |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | public void addListener(IntentEventListener listener) { |
| 160 | intentManager.addListener(listener); |
| 161 | } |
| 162 | |
| 163 | @Override |
| 164 | public void removeListener(IntentEventListener listener) { |
| 165 | intentManager.removeListener(listener); |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public <T extends Intent> void registerCompiler(Class<T> cls, IntentCompiler<T> compiler) { |
| 170 | intentManager.registerCompiler(cls, compiler); |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public <T extends Intent> void unregisterCompiler(Class<T> cls) { |
| 175 | intentManager.unregisterCompiler(cls); |
| 176 | } |
| 177 | |
| 178 | @Override |
| 179 | public Map<Class<? extends Intent>, IntentCompiler<? extends Intent>> getCompilers() { |
| 180 | return intentManager.getCompilers(); |
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public <T extends InstallableIntent> void registerInstaller(Class<T> cls, IntentInstaller<T> installer) { |
| 185 | intentManager.registerInstaller(cls, installer); |
| 186 | } |
| 187 | |
| 188 | @Override |
| 189 | public <T extends InstallableIntent> void unregisterInstaller(Class<T> cls) { |
| 190 | intentManager.unregisterInstaller(cls); |
| 191 | } |
| 192 | |
| 193 | @Override |
| 194 | public Map<Class<? extends InstallableIntent>, IntentInstaller<? extends InstallableIntent>> getInstallers() { |
| 195 | return intentManager.getInstallers(); |
| 196 | } |
| 197 | } |