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