blob: 3ac988215c0ca51b52c907a1a6204267a6f5aa94 [file] [log] [blame]
Sho SHIMIZU47441512014-08-26 10:14:22 -07001package net.onrc.onos.core.newintent;
2
Jonathan Hart68e8dd62014-08-26 18:06:23 -07003import java.util.ArrayList;
4import java.util.Arrays;
5import java.util.Collection;
6import java.util.HashMap;
7import java.util.Map;
8import java.util.Set;
9
Sho SHIMIZU47441512014-08-26 10:14:22 -070010import net.floodlightcontroller.core.module.FloodlightModuleContext;
11import net.floodlightcontroller.core.module.FloodlightModuleException;
12import net.floodlightcontroller.core.module.IFloodlightModule;
13import net.floodlightcontroller.core.module.IFloodlightService;
Jonathan Hart68e8dd62014-08-26 18:06:23 -070014import net.floodlightcontroller.restserver.IRestApiService;
Sho SHIMIZU7cd8a422014-08-27 16:05:21 -070015import net.onrc.onos.api.flowmanager.FlowId;
Sho SHIMIZU47441512014-08-26 10:14:22 -070016import net.onrc.onos.api.flowmanager.FlowManagerFloodlightService;
17import net.onrc.onos.api.flowmanager.FlowManagerService;
18import net.onrc.onos.api.newintent.InstallableIntent;
19import net.onrc.onos.api.newintent.Intent;
20import net.onrc.onos.api.newintent.IntentCompiler;
21import net.onrc.onos.api.newintent.IntentEventListener;
22import net.onrc.onos.api.newintent.IntentFloodlightService;
23import net.onrc.onos.api.newintent.IntentId;
Sho SHIMIZU47441512014-08-26 10:14:22 -070024import net.onrc.onos.api.newintent.IntentInstaller;
25import net.onrc.onos.api.newintent.IntentManager;
26import net.onrc.onos.api.newintent.IntentOperations;
27import net.onrc.onos.api.newintent.IntentState;
28import net.onrc.onos.api.newintent.MultiPointToSinglePointIntent;
29import net.onrc.onos.api.newintent.PathIntent;
30import net.onrc.onos.api.newintent.PointToPointIntent;
31import net.onrc.onos.core.datagrid.ISharedCollectionsService;
Jonathan Hart68e8dd62014-08-26 18:06:23 -070032import net.onrc.onos.core.newintent.web.IntentWebRoutable;
Sho SHIMIZU47441512014-08-26 10:14:22 -070033import net.onrc.onos.core.registry.IControllerRegistryService;
34import net.onrc.onos.core.topology.ITopologyService;
35import net.onrc.onos.core.util.IdBlockAllocator;
Sho SHIMIZU7cd8a422014-08-27 16:05:21 -070036import net.onrc.onos.core.util.IdGenerator;
Sho SHIMIZU47441512014-08-26 10:14:22 -070037
Sho SHIMIZU47441512014-08-26 10:14:22 -070038/**
39 * A Floodlight module for Intent Service.
40 */
41public 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 Hart68e8dd62014-08-26 18:06:23 -070054 impls.put(IntentFloodlightService.class, this);
Sho SHIMIZU47441512014-08-26 10:14:22 -070055 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 SHIMIZU7cd8a422014-08-27 16:05:21 -070081 IdGenerator<IntentId> intentIdGenerator =
Sho SHIMIZU47441512014-08-26 10:14:22 -070082 new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator);
83 FlowManagerService flowManagerService =
84 context.getServiceImpl(FlowManagerFloodlightService.class);
Sho SHIMIZU7cd8a422014-08-27 16:05:21 -070085 IdGenerator<FlowId> flowIdGenerator =
Sho SHIMIZU47441512014-08-26 10:14:22 -070086 flowManagerService.getFlowIdGenerator();
87
88 ITopologyService topologyService =
89 context.getServiceImpl(ITopologyService.class);
90
91 registerDefaultCompilers(intentIdGenerator, flowIdGenerator, topologyService);
92 registerDefaultInstallers(flowManagerService);
Jonathan Hart68e8dd62014-08-26 18:06:23 -070093
94 IRestApiService restApi = context.getServiceImpl(IRestApiService.class);
95 restApi.addRestletRoutable(new IntentWebRoutable());
Sho SHIMIZU47441512014-08-26 10:14:22 -070096 }
97
Sho SHIMIZU7cd8a422014-08-27 16:05:21 -070098 private void registerDefaultCompilers(IdGenerator<IntentId> intentIdGenerator,
99 IdGenerator<FlowId> flowIdGenerator,
Sho SHIMIZU47441512014-08-26 10:14:22 -0700100 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}