blob: 3c33dc4aeeffe8640721d60cc7510e2a288f9c24 [file] [log] [blame]
jaegonkimdcf7c822019-02-06 15:00:14 +09001/*
2 * Copyright 2019-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.ofoverlay.impl;
17
18import org.onosproject.net.device.DeviceService;
19import org.onosproject.workflow.api.ImmutableListWorkflow;
20import org.onosproject.workflow.api.Workflow;
21import org.onosproject.workflow.api.WorkflowExecutionService;
22import org.onosproject.workflow.api.WorkflowStore;
23import org.onosproject.workflow.api.WorkplaceStore;
m.rahil09251882019-04-15 22:58:33 +053024import org.onosproject.workflow.api.DefaultWorkletDescription;
25import org.onosproject.workflow.api.WorkflowException;
jaegonkimdcf7c822019-02-06 15:00:14 +090026import org.osgi.service.component.annotations.Activate;
27import org.osgi.service.component.annotations.Component;
28import org.osgi.service.component.annotations.Deactivate;
29import org.osgi.service.component.annotations.Reference;
30import org.osgi.service.component.annotations.ReferenceCardinality;
31import org.slf4j.Logger;
32import org.slf4j.LoggerFactory;
33
34import java.net.URI;
35import java.util.concurrent.ScheduledExecutorService;
36
37import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
38import static org.onlab.util.Tools.groupedThreads;
39
40/**
DongRyeol Chad3d8f032019-12-24 10:29:36 +090041 * Class for Open-flow overlay configuration workflow registration.
jaegonkimdcf7c822019-02-06 15:00:14 +090042 */
43@Component(immediate = true)
DongRyeol Chad3d8f032019-12-24 10:29:36 +090044public class OfOverlayWorkflowRegister {
jaegonkimdcf7c822019-02-06 15:00:14 +090045
DongRyeol Chad3d8f032019-12-24 10:29:36 +090046 private static final Logger log = LoggerFactory.getLogger(OfOverlayWorkflowRegister.class);
jaegonkimdcf7c822019-02-06 15:00:14 +090047
48 @Reference(cardinality = ReferenceCardinality.MANDATORY)
49 protected WorkflowStore workflowStore;
50
51 @Reference(cardinality = ReferenceCardinality.MANDATORY)
52 protected WorkplaceStore workplaceStore;
53
54 @Reference(cardinality = ReferenceCardinality.MANDATORY)
55 protected WorkflowExecutionService workflowExecutionService;
56
57 @Reference(cardinality = ReferenceCardinality.MANDATORY)
58 protected DeviceService deviceService;
59
60 private ScheduledExecutorService eventMapTriggerExecutor;
61
m.rahil09251882019-04-15 22:58:33 +053062 private static final String BRIDGE_NAME = "/bridgeName";
63
jaegonkimdcf7c822019-02-06 15:00:14 +090064 @Activate
65 public void activate() {
66 log.info("Activated");
67
68 eventMapTriggerExecutor = newSingleThreadScheduledExecutor(
69 groupedThreads("onos/of-overlay", "eventmap-trigger-executor"));
70
71 registerWorkflows();
72
73 }
74
75 @Deactivate
76 public void deactivate() {
77 log.info("Deactivated");
78 }
79
80 /**
81 * Registers workflows.
82 */
83 private void registerWorkflows() {
m.rahil09251882019-04-15 22:58:33 +053084 try {
85 // registering class-loader
86 workflowStore.registerLocal(this.getClass().getClassLoader());
jaegonkimdcf7c822019-02-06 15:00:14 +090087
m.rahil09251882019-04-15 22:58:33 +053088 // registering new workflow definition
89 URI uri = URI.create("of-overlay.workflow-nova");
90 Workflow workflow = ImmutableListWorkflow.builder()
91 .id(uri)
92 //.attribute(WorkflowAttribute.REMOVE_AFTER_COMPLETE)
93 .chain(Ovs.CreateOvsdbDevice.class.getName())
94 .chain(Ovs.UpdateOvsVersion.class.getName())
m.rahilfaf04d72019-05-24 21:11:22 +053095 .chain(Ovs.UpdateBridgeId.class.getName())
m.rahil09251882019-04-15 22:58:33 +053096 .chain(DefaultWorkletDescription.builder().name(Ovs.CreateBridge.class.getName())
97 .staticDataModel(BRIDGE_NAME, "br-int")
98 .build())
m.rahil09251882019-04-15 22:58:33 +053099 .chain(DefaultWorkletDescription.builder().name(Ovs.CreateBridge.class.getName())
100 .staticDataModel(BRIDGE_NAME, "br-phy")
101 .build())
102 .chain(Ovs.CreateOverlayBridgeVxlanPort.class.getName())
103 .chain(Ovs.AddPhysicalPortsOnUnderlayBridge.class.getName())
104 .chain(Ovs.ConfigureUnderlayBridgeLocalIp.class.getName())
105 .build();
jaegonkimdcf7c822019-02-06 15:00:14 +0900106
m.rahil09251882019-04-15 22:58:33 +0530107 workflowStore.register(workflow);
nitinanand2a5c8fd2019-03-20 10:26:08 +0530108
nitinanandc8b70252019-04-17 15:35:43 +0530109 // registering new workflow definition
110 uri = URI.create("of-overlay.workflow-nova-with-trigger-to-restart");
111 workflow = ImmutableListWorkflow.builder()
112 .id(uri)
113 //.attribute(WorkflowAttribute.REMOVE_AFTER_COMPLETE)
114 .chain(Ovs.CreateOvsdbDevice.class.getName())
115 .chain(Ovs.UpdateOvsVersion.class.getName())
116 .chain(Ovs.UpdateBridgeId.class.getName())
117 .chain(DefaultWorkletDescription.builder().name(Ovs.CreateBridge.class.getName())
118 .staticDataModel(BRIDGE_NAME, "br-int")
119 .build())
120 .chain(DefaultWorkletDescription.builder().name(Ovs.CreateBridge.class.getName())
121 .staticDataModel(BRIDGE_NAME, "br-phy")
122 .build())
123 .chain(Ovs.CreateOverlayBridgeVxlanPort.class.getName())
124 .chain(Ovs.AddPhysicalPortsOnUnderlayBridge.class.getName())
125 .chain(Ovs.ConfigureUnderlayBridgeLocalIp.class.getName())
126 .trigger(Ovs.TrigerWorkflowAtDeviceReboot.class.getName())
127 .build();
128 workflowStore.register(workflow);
129
130
131
m.rahil09251882019-04-15 22:58:33 +0530132 // registering new workflow definition based on multi-event handling
133 uri = URI.create("of-overlay.workflow-nova-multiEvent-test");
134 workflow = ImmutableListWorkflow.builder()
135 .id(uri)
136 //.attribute(WorkflowAttribute.REMOVE_AFTER_COMPLETE)
137 .chain(Ovs.CreateOvsdbDevice.class.getName())
138 .chain(Ovs.UpdateOvsVersion.class.getName())
m.rahilfaf04d72019-05-24 21:11:22 +0530139 .chain(Ovs.UpdateBridgeId.class.getName())
m.rahil09251882019-04-15 22:58:33 +0530140 .chain(Ovs.CreateOverlayBridgeMultiEvent.class.getName())
m.rahilfaf04d72019-05-24 21:11:22 +0530141 .chain(Ovs.UpdateBridgeId.class.getName())
142 .chain(DefaultWorkletDescription.builder().name(Ovs.CreateBridge.class.getName())
143 .staticDataModel(BRIDGE_NAME, "br-phy")
144 .build())
m.rahil09251882019-04-15 22:58:33 +0530145 .chain(Ovs.CreateOverlayBridgeVxlanPort.class.getName())
146 .chain(Ovs.AddPhysicalPortsOnUnderlayBridge.class.getName())
147 .chain(Ovs.ConfigureUnderlayBridgeLocalIp.class.getName())
148 .build();
149 workflowStore.register(workflow);
jaegonkimdcf7c822019-02-06 15:00:14 +0900150
m.rahil09251882019-04-15 22:58:33 +0530151 uri = URI.create("of-overlay.clean-workflow-nova");
152 workflow = ImmutableListWorkflow.builder()
153 .id(uri)
154 //.attribute(WorkflowAttribute.REMOVE_AFTER_COMPLETE)
155 .chain(Ovs.DeleteOverlayBridgeConfig.class.getName())
156 .chain(Ovs.RemoveOverlayBridgeOfDevice.class.getName())
157 .chain(Ovs.DeleteUnderlayBridgeConfig.class.getName())
158 .chain(Ovs.RemoveUnderlayBridgeOfDevice.class.getName())
159 .chain(Ovs.RemoveOvsdbDevice.class.getName())
160 .build();
161 workflowStore.register(workflow);
nitinanand0a15a162019-03-27 15:38:09 +0530162
m.rahil09251882019-04-15 22:58:33 +0530163 uri = URI.create("of-overlay.clean-workflow-nova-waitAll-Bridge-Del");
164 workflow = ImmutableListWorkflow.builder()
165 .id(uri)
166 //.attribute(WorkflowAttribute.REMOVE_AFTER_COMPLETE)
167 .chain(Ovs.DeleteOverlayBridgeConfig.class.getName())
168 .chain(Ovs.DeleteUnderlayBridgeConfig.class.getName())
169 .chain(Ovs.RemoveBridgeOfDevice.class.getName())
170 .chain(Ovs.RemoveOvsdbDevice.class.getName())
171 .build();
172 workflowStore.register(workflow);
jaegonkimdcf7c822019-02-06 15:00:14 +0900173
m.rahil09251882019-04-15 22:58:33 +0530174 uri = URI.create("of-overlay.workflow-ovs-leaf");
175 workflow = ImmutableListWorkflow.builder()
176 .id(uri)
177 .chain(Ovs.CreateOvsdbDevice.class.getName())
178 .chain(Ovs.UpdateOvsVersion.class.getName())
m.rahilfaf04d72019-05-24 21:11:22 +0530179 .chain(Ovs.UpdateBridgeId.class.getName())
180 .chain(DefaultWorkletDescription.builder().name(Ovs.CreateBridge.class.getName())
181 .staticDataModel(BRIDGE_NAME, "br-phy")
182 .build())
m.rahil09251882019-04-15 22:58:33 +0530183 .chain(Ovs.AddPhysicalPortsOnUnderlayBridge.class.getName())
184 .build();
185 workflowStore.register(workflow);
jaegonkimdcf7c822019-02-06 15:00:14 +0900186
m.rahil09251882019-04-15 22:58:33 +0530187 uri = URI.create("of-overlay.workflow-ovs-spine");
188 workflow = ImmutableListWorkflow.builder()
189 .id(uri)
190 .chain(Ovs.CreateOvsdbDevice.class.getName())
191 .chain(Ovs.UpdateOvsVersion.class.getName())
m.rahilfaf04d72019-05-24 21:11:22 +0530192 .chain(Ovs.UpdateBridgeId.class.getName())
193 .chain(DefaultWorkletDescription.builder().name(Ovs.CreateBridge.class.getName())
194 .staticDataModel(BRIDGE_NAME, "br-phy")
195 .build())
m.rahil09251882019-04-15 22:58:33 +0530196 .chain(Ovs.AddPhysicalPortsOnUnderlayBridge.class.getName())
197 .build();
198 workflowStore.register(workflow);
199
200 deviceService.addListener(
201 event -> {
202 // trigger EventTask for DeviceEvent
203 eventMapTriggerExecutor.submit(
204 () -> workflowExecutionService.eventMapTrigger(
205 event,
206 // event hint supplier
207 (ev) -> {
208 if (ev == null || ev.subject() == null) {
209 return null;
210 }
211 String hint = event.subject().id().toString();
212 log.debug("hint: {}", hint);
213 return hint;
nitinanandc8b70252019-04-17 15:35:43 +0530214
jaegonkimdcf7c822019-02-06 15:00:14 +0900215 }
m.rahil09251882019-04-15 22:58:33 +0530216 )
217 );
218 }
219 );
jaegonkimdcf7c822019-02-06 15:00:14 +0900220
m.rahil09251882019-04-15 22:58:33 +0530221 } catch (WorkflowException e) {
222 e.printStackTrace();
223 }
jaegonkimdcf7c822019-02-06 15:00:14 +0900224 }
225
226}