blob: cf0e5e567d7ba9696bab741f00df1b764a15fcc2 [file] [log] [blame]
Sho SHIMIZU47441512014-08-26 10:14:22 -07001package net.onrc.onos.core.newintent;
2
3import net.floodlightcontroller.core.module.FloodlightModuleContext;
4import net.floodlightcontroller.core.module.FloodlightModuleException;
5import net.floodlightcontroller.core.module.IFloodlightModule;
6import net.floodlightcontroller.core.module.IFloodlightService;
Sho SHIMIZU7cd8a422014-08-27 16:05:21 -07007import net.onrc.onos.api.flowmanager.FlowId;
Sho SHIMIZU47441512014-08-26 10:14:22 -07008import net.onrc.onos.api.flowmanager.FlowManagerFloodlightService;
9import net.onrc.onos.api.flowmanager.FlowManagerService;
10import net.onrc.onos.api.newintent.InstallableIntent;
11import net.onrc.onos.api.newintent.Intent;
12import net.onrc.onos.api.newintent.IntentCompiler;
13import net.onrc.onos.api.newintent.IntentEventListener;
14import net.onrc.onos.api.newintent.IntentFloodlightService;
15import net.onrc.onos.api.newintent.IntentId;
Sho SHIMIZU47441512014-08-26 10:14:22 -070016import net.onrc.onos.api.newintent.IntentInstaller;
17import net.onrc.onos.api.newintent.IntentManager;
18import net.onrc.onos.api.newintent.IntentOperations;
19import net.onrc.onos.api.newintent.IntentState;
20import net.onrc.onos.api.newintent.MultiPointToSinglePointIntent;
21import net.onrc.onos.api.newintent.PathIntent;
22import net.onrc.onos.api.newintent.PointToPointIntent;
23import net.onrc.onos.core.datagrid.ISharedCollectionsService;
24import net.onrc.onos.core.registry.IControllerRegistryService;
25import net.onrc.onos.core.topology.ITopologyService;
26import net.onrc.onos.core.util.IdBlockAllocator;
Sho SHIMIZU7cd8a422014-08-27 16:05:21 -070027import net.onrc.onos.core.util.IdGenerator;
Sho SHIMIZU47441512014-08-26 10:14:22 -070028
29import java.util.ArrayList;
30import java.util.Arrays;
31import java.util.Collection;
32import java.util.HashMap;
33import java.util.Map;
34import java.util.Set;
35
36/**
37 * A Floodlight module for Intent Service.
38 */
39public 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 SHIMIZU7cd8a422014-08-27 16:05:21 -070079 IdGenerator<IntentId> intentIdGenerator =
Sho SHIMIZU47441512014-08-26 10:14:22 -070080 new IdBlockAllocatorBasedIntentIdGenerator(idBlockAllocator);
81 FlowManagerService flowManagerService =
82 context.getServiceImpl(FlowManagerFloodlightService.class);
Sho SHIMIZU7cd8a422014-08-27 16:05:21 -070083 IdGenerator<FlowId> flowIdGenerator =
Sho SHIMIZU47441512014-08-26 10:14:22 -070084 flowManagerService.getFlowIdGenerator();
85
86 ITopologyService topologyService =
87 context.getServiceImpl(ITopologyService.class);
88
89 registerDefaultCompilers(intentIdGenerator, flowIdGenerator, topologyService);
90 registerDefaultInstallers(flowManagerService);
91 }
92
Sho SHIMIZU7cd8a422014-08-27 16:05:21 -070093 private void registerDefaultCompilers(IdGenerator<IntentId> intentIdGenerator,
94 IdGenerator<FlowId> flowIdGenerator,
Sho SHIMIZU47441512014-08-26 10:14:22 -070095 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}