Jonathan Hart
Committed by Gerrit Code Review

Provision flows on OLT and fabric when we add a vOLT tenant

Change-Id: I22a73c6c2c472155408ba109f0d21b5907107857
...@@ -15,11 +15,12 @@ ...@@ -15,11 +15,12 @@
15 */ 15 */
16 package org.onosproject.xosintegration; 16 package org.onosproject.xosintegration;
17 17
18 -import java.util.Dictionary; 18 +import com.eclipsesource.json.JsonArray;
19 -import java.util.Set; 19 +import com.eclipsesource.json.JsonObject;
20 -import java.util.stream.Collectors; 20 +import com.sun.jersey.api.client.Client;
21 -import java.util.stream.IntStream; 21 +import com.sun.jersey.api.client.ClientResponse;
22 - 22 +import com.sun.jersey.api.client.WebResource;
23 +import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
23 import org.apache.felix.scr.annotations.Activate; 24 import org.apache.felix.scr.annotations.Activate;
24 import org.apache.felix.scr.annotations.Component; 25 import org.apache.felix.scr.annotations.Component;
25 import org.apache.felix.scr.annotations.Deactivate; 26 import org.apache.felix.scr.annotations.Deactivate;
...@@ -28,19 +29,28 @@ import org.apache.felix.scr.annotations.Property; ...@@ -28,19 +29,28 @@ import org.apache.felix.scr.annotations.Property;
28 import org.apache.felix.scr.annotations.Reference; 29 import org.apache.felix.scr.annotations.Reference;
29 import org.apache.felix.scr.annotations.ReferenceCardinality; 30 import org.apache.felix.scr.annotations.ReferenceCardinality;
30 import org.apache.felix.scr.annotations.Service; 31 import org.apache.felix.scr.annotations.Service;
32 +import org.onlab.packet.VlanId;
31 import org.onlab.util.Tools; 33 import org.onlab.util.Tools;
32 import org.onosproject.cfg.ComponentConfigService; 34 import org.onosproject.cfg.ComponentConfigService;
33 import org.onosproject.core.ApplicationId; 35 import org.onosproject.core.ApplicationId;
34 import org.onosproject.core.CoreService; 36 import org.onosproject.core.CoreService;
37 +import org.onosproject.net.ConnectPoint;
38 +import org.onosproject.net.DeviceId;
39 +import org.onosproject.net.PortNumber;
40 +import org.onosproject.net.flow.DefaultTrafficSelector;
41 +import org.onosproject.net.flow.DefaultTrafficTreatment;
42 +import org.onosproject.net.flow.TrafficSelector;
43 +import org.onosproject.net.flow.TrafficTreatment;
44 +import org.onosproject.net.flowobjective.DefaultForwardingObjective;
45 +import org.onosproject.net.flowobjective.FlowObjectiveService;
46 +import org.onosproject.net.flowobjective.ForwardingObjective;
35 import org.osgi.service.component.ComponentContext; 47 import org.osgi.service.component.ComponentContext;
36 import org.slf4j.Logger; 48 import org.slf4j.Logger;
37 49
38 -import com.eclipsesource.json.JsonArray; 50 +import java.util.Dictionary;
39 -import com.eclipsesource.json.JsonObject; 51 +import java.util.Set;
40 -import com.sun.jersey.api.client.Client; 52 +import java.util.stream.Collectors;
41 -import com.sun.jersey.api.client.ClientResponse; 53 +import java.util.stream.IntStream;
42 -import com.sun.jersey.api.client.WebResource;
43 -import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
44 54
45 import static com.google.common.base.Strings.isNullOrEmpty; 55 import static com.google.common.base.Strings.isNullOrEmpty;
46 import static com.google.common.net.MediaType.JSON_UTF_8; 56 import static com.google.common.net.MediaType.JSON_UTF_8;
...@@ -68,12 +78,26 @@ public class OnosXOSIntegrationManager implements VoltTenantService { ...@@ -68,12 +78,26 @@ public class OnosXOSIntegrationManager implements VoltTenantService {
68 private static final String XOS_TENANT_BASE_URI = "/xoslib/volttenant/"; 78 private static final String XOS_TENANT_BASE_URI = "/xoslib/volttenant/";
69 private static final int TEST_XOS_PROVIDER_SERVICE = 1; 79 private static final int TEST_XOS_PROVIDER_SERVICE = 1;
70 80
81 + private static final DeviceId FABRIC_DEVICE_ID = DeviceId.deviceId("of:5e3e486e73000187");
82 + private static final PortNumber FABRIC_OLT_CONNECT_POINT = PortNumber.portNumber(2);
83 + private static final PortNumber FABRIC_VCPE_CONNECT_POINT = PortNumber.portNumber(3);
84 + private static final String FABRIC_CONTROLLER_ADDRESS = "10.0.3.136";
85 + private static final int FABRIC_SERVER_PORT = 8181;
86 + private static final String FABRIC_BASE_URI = "/onos/cordfabric/vlans/add";
87 +
88 + private static final ConnectPoint FABRIC_PORT = new ConnectPoint(
89 + DeviceId.deviceId("of:000090e2ba82f974"),
90 + PortNumber.portNumber(2));
91 +
71 private final Logger log = getLogger(getClass()); 92 private final Logger log = getLogger(getClass());
72 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 93 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
73 protected CoreService coreService; 94 protected CoreService coreService;
74 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 95 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
75 protected ComponentConfigService cfgService; 96 protected ComponentConfigService cfgService;
76 97
98 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
99 + protected FlowObjectiveService flowObjectiveService;
100 +
77 @Property(name = XOS_SERVER_ADDRESS_PROPERTY_NAME, 101 @Property(name = XOS_SERVER_ADDRESS_PROPERTY_NAME,
78 value = TEST_XOS_SERVER_ADDRESS, 102 value = TEST_XOS_SERVER_ADDRESS,
79 label = "XOS Server address") 103 label = "XOS Server address")
...@@ -267,9 +291,16 @@ public class OnosXOSIntegrationManager implements VoltTenantService { ...@@ -267,9 +291,16 @@ public class OnosXOSIntegrationManager implements VoltTenantService {
267 .withProviderService(providerServiceId) 291 .withProviderService(providerServiceId)
268 .withServiceSpecificId(newTenant.serviceSpecificId()) 292 .withServiceSpecificId(newTenant.serviceSpecificId())
269 .withVlanId(newTenant.vlanId()) 293 .withVlanId(newTenant.vlanId())
294 + .withPort(newTenant.port())
270 .build(); 295 .build();
271 String json = tenantToJson(tenantToCreate); 296 String json = tenantToJson(tenantToCreate);
297 +
298 + provisionDataPlane(tenantToCreate);
299 +
272 postRest(json); 300 postRest(json);
301 +
302 + provisionFabric(VlanId.vlanId(Short.parseShort(newTenant.vlanId())));
303 +
273 return newTenant; 304 return newTenant;
274 } 305 }
275 306
...@@ -284,6 +315,72 @@ public class OnosXOSIntegrationManager implements VoltTenantService { ...@@ -284,6 +315,72 @@ public class OnosXOSIntegrationManager implements VoltTenantService {
284 } 315 }
285 } 316 }
286 317
318 + private void provisionDataPlane(VoltTenant tenant) {
319 + VlanId vlan = VlanId.vlanId(Short.parseShort(tenant.vlanId()));
320 +
321 + TrafficSelector fromGateway = DefaultTrafficSelector.builder()
322 + .matchInPhyPort(tenant.port().port())
323 + .build();
324 +
325 + TrafficSelector fromFabric = DefaultTrafficSelector.builder()
326 + .matchInPhyPort(FABRIC_PORT.port())
327 + .matchVlanId(vlan)
328 + .build();
329 +
330 + TrafficTreatment toFabric = DefaultTrafficTreatment.builder()
331 + .pushVlan()
332 + .setVlanId(vlan)
333 + .setOutput(FABRIC_PORT.port())
334 + .build();
335 +
336 + TrafficTreatment toGateway = DefaultTrafficTreatment.builder()
337 + .popVlan()
338 + .setOutput(tenant.port().port())
339 + .build();
340 +
341 + ForwardingObjective forwardToFabric = DefaultForwardingObjective.builder()
342 + .withFlag(ForwardingObjective.Flag.VERSATILE)
343 + .withPriority(1000)
344 + .makePermanent()
345 + .fromApp(appId)
346 + .withSelector(fromGateway)
347 + .withTreatment(toFabric)
348 + .add();
349 +
350 + ForwardingObjective forwardToGateway = DefaultForwardingObjective.builder()
351 + .withFlag(ForwardingObjective.Flag.VERSATILE)
352 + .withPriority(1000)
353 + .makePermanent()
354 + .fromApp(appId)
355 + .withSelector(fromFabric)
356 + .withTreatment(toGateway)
357 + .add();
358 +
359 + flowObjectiveService.forward(FABRIC_PORT.deviceId(), forwardToFabric);
360 + flowObjectiveService.forward(FABRIC_PORT.deviceId(), forwardToGateway);
361 + }
362 +
363 + private void provisionFabric(VlanId vlanId) {
364 + String json = "{\"vlan\":" + vlanId + ",\"ports\":[";
365 + json += "{\"device\":\"" + FABRIC_DEVICE_ID.toString() + "\",\"port\":\""
366 + + FABRIC_OLT_CONNECT_POINT.toString() + "\"},";
367 + json += "{\"device\":\"" + FABRIC_DEVICE_ID.toString() + "\",\"port\":\""
368 + + FABRIC_VCPE_CONNECT_POINT.toString() + "\"}";
369 + json += "]}";
370 +
371 + String baseUrl = "http://" + FABRIC_CONTROLLER_ADDRESS + ":"
372 + + Integer.toString(FABRIC_SERVER_PORT);
373 + Client client = Client.create();
374 + client.addFilter(new HTTPBasicAuthFilter("padmin@vicci.org", "letmein"));
375 + WebResource resource = client.resource(baseUrl
376 + + FABRIC_BASE_URI);
377 + WebResource.Builder builder = resource.accept(JSON_UTF_8.toString())
378 + .type(JSON_UTF_8.toString());
379 +
380 + ClientResponse response = builder.post(ClientResponse.class, json);
381 +
382 + }
383 +
287 /** 384 /**
288 * Extracts properties from the component configuration context. 385 * Extracts properties from the component configuration context.
289 * 386 *
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
16 package org.onosproject.xosintegration; 16 package org.onosproject.xosintegration;
17 17
18 import com.google.common.base.MoreObjects; 18 import com.google.common.base.MoreObjects;
19 +import org.onosproject.net.ConnectPoint;
19 20
20 public final class VoltTenant { 21 public final class VoltTenant {
21 22
...@@ -24,6 +25,7 @@ public final class VoltTenant { ...@@ -24,6 +25,7 @@ public final class VoltTenant {
24 private final long providerService; 25 private final long providerService;
25 private final String serviceSpecificId; 26 private final String serviceSpecificId;
26 private final String vlanId; 27 private final String vlanId;
28 + private final ConnectPoint port;
27 29
28 /** 30 /**
29 * Constructs a vOLT tenant object. 31 * Constructs a vOLT tenant object.
...@@ -35,12 +37,13 @@ public final class VoltTenant { ...@@ -35,12 +37,13 @@ public final class VoltTenant {
35 * @param vlanId vlan id for the user 37 * @param vlanId vlan id for the user
36 */ 38 */
37 private VoltTenant(String humanReadableName, long id, long providerService, 39 private VoltTenant(String humanReadableName, long id, long providerService,
38 - String serviceSpecificId, String vlanId) { 40 + String serviceSpecificId, String vlanId, ConnectPoint port) {
39 this.humanReadableName = humanReadableName; 41 this.humanReadableName = humanReadableName;
40 this.id = id; 42 this.id = id;
41 this.providerService = providerService; 43 this.providerService = providerService;
42 this.serviceSpecificId = serviceSpecificId; 44 this.serviceSpecificId = serviceSpecificId;
43 this.vlanId = vlanId; 45 this.vlanId = vlanId;
46 + this.port = port;
44 } 47 }
45 48
46 /** 49 /**
...@@ -97,6 +100,10 @@ public final class VoltTenant { ...@@ -97,6 +100,10 @@ public final class VoltTenant {
97 return vlanId; 100 return vlanId;
98 } 101 }
99 102
103 + public ConnectPoint port() {
104 + return port;
105 + }
106 +
100 /** 107 /**
101 * Builder class to allow callers to assemble tenants. 108 * Builder class to allow callers to assemble tenants.
102 */ 109 */
...@@ -107,6 +114,7 @@ public final class VoltTenant { ...@@ -107,6 +114,7 @@ public final class VoltTenant {
107 private long providerService = -1; 114 private long providerService = -1;
108 private String serviceSpecificId = "unknown"; 115 private String serviceSpecificId = "unknown";
109 private String vlanId = "unknown"; 116 private String vlanId = "unknown";
117 + private ConnectPoint port;
110 118
111 /** 119 /**
112 * Sets the name string for the tenant. 120 * Sets the name string for the tenant.
...@@ -163,6 +171,11 @@ public final class VoltTenant { ...@@ -163,6 +171,11 @@ public final class VoltTenant {
163 return this; 171 return this;
164 } 172 }
165 173
174 + public Builder withPort(ConnectPoint port) {
175 + this.port = port;
176 + return this;
177 + }
178 +
166 /** 179 /**
167 * Constructs a VoltTenant from the assembled data. 180 * Constructs a VoltTenant from the assembled data.
168 * 181 *
...@@ -170,7 +183,7 @@ public final class VoltTenant { ...@@ -170,7 +183,7 @@ public final class VoltTenant {
170 */ 183 */
171 public VoltTenant build() { 184 public VoltTenant build() {
172 return new VoltTenant(humanReadableName, id, providerService, 185 return new VoltTenant(humanReadableName, id, providerService,
173 - serviceSpecificId, vlanId); 186 + serviceSpecificId, vlanId, port);
174 } 187 }
175 } 188 }
176 189
...@@ -182,6 +195,7 @@ public final class VoltTenant { ...@@ -182,6 +195,7 @@ public final class VoltTenant {
182 .add("providerService", providerService()) 195 .add("providerService", providerService())
183 .add("serviceSpecificId", serviceSpecificId()) 196 .add("serviceSpecificId", serviceSpecificId())
184 .add("vlanId", vlanId()) 197 .add("vlanId", vlanId())
198 + .add("port", port())
185 .toString(); 199 .toString();
186 } 200 }
187 201
......
...@@ -18,6 +18,7 @@ package org.onosproject.xosintegration.cli; ...@@ -18,6 +18,7 @@ package org.onosproject.xosintegration.cli;
18 import org.apache.karaf.shell.commands.Argument; 18 import org.apache.karaf.shell.commands.Argument;
19 import org.apache.karaf.shell.commands.Command; 19 import org.apache.karaf.shell.commands.Command;
20 import org.onosproject.cli.AbstractShellCommand; 20 import org.onosproject.cli.AbstractShellCommand;
21 +import org.onosproject.net.ConnectPoint;
21 import org.onosproject.xosintegration.VoltTenant; 22 import org.onosproject.xosintegration.VoltTenant;
22 import org.onosproject.xosintegration.VoltTenantService; 23 import org.onosproject.xosintegration.VoltTenantService;
23 24
...@@ -38,6 +39,11 @@ public class VoltTenantsCreateCommand extends AbstractShellCommand { ...@@ -38,6 +39,11 @@ public class VoltTenantsCreateCommand extends AbstractShellCommand {
38 required = true, multiValued = false) 39 required = true, multiValued = false)
39 String vlanId; 40 String vlanId;
40 41
42 + @Argument(index = 2, name = "port",
43 + description = "Port",
44 + required = true, multiValued = false)
45 + String port;
46 +
41 @Override 47 @Override
42 protected void execute() { 48 protected void execute() {
43 VoltTenantService service = get(VoltTenantService.class); 49 VoltTenantService service = get(VoltTenantService.class);
...@@ -45,7 +51,9 @@ public class VoltTenantsCreateCommand extends AbstractShellCommand { ...@@ -45,7 +51,9 @@ public class VoltTenantsCreateCommand extends AbstractShellCommand {
45 VoltTenant newTenant = VoltTenant.builder() 51 VoltTenant newTenant = VoltTenant.builder()
46 .withServiceSpecificId(serviceSpecificId) 52 .withServiceSpecificId(serviceSpecificId)
47 .withVlanId(vlanId) 53 .withVlanId(vlanId)
54 + .withPort(ConnectPoint.deviceConnectPoint(port))
48 .build(); 55 .build();
56 +
49 service.addTenant(newTenant); 57 service.addTenant(newTenant);
50 } 58 }
51 } 59 }
......
...@@ -29,9 +29,13 @@ ...@@ -29,9 +29,13 @@
29 <action class="org.onosproject.xosintegration.cli.VoltRemoveTenantCommand"/> 29 <action class="org.onosproject.xosintegration.cli.VoltRemoveTenantCommand"/>
30 <completers> 30 <completers>
31 <ref component-id="tenantIdCompleter"/> 31 <ref component-id="tenantIdCompleter"/>
32 + <ref component-id="placeholderCompleter"/>
33 + <ref component-id="connectPointCompleter"/>
32 <null/> 34 <null/>
33 </completers> 35 </completers>
34 </command> 36 </command>
35 </command-bundle> 37 </command-bundle>
36 <bean id="tenantIdCompleter" class="org.onosproject.xosintegration.cli.TenantIdCompleter"/> 38 <bean id="tenantIdCompleter" class="org.onosproject.xosintegration.cli.TenantIdCompleter"/>
39 + <bean id="placeholderCompleter" class="org.onosproject.cli.PlaceholderCompleter"/>
40 + <bean id="connectPointCompleter" class="org.onosproject.cli.net.ConnectPointCompleter"/>
37 </blueprint> 41 </blueprint>
......