jcc
Committed by Brian O'Connor

[ONOS-1284][ONOS-1869]the implementation of tunnel subsystem.It includes

test
commands, store, service. the store use eventually consistent.

Change-Id: Id54224ff65f3f2fa0a1d7adb072a2fe664987d18
1 +/*
2 + * Copyright 2014-2015 Open Networking Laboratory
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 + */
16 +package org.onosproject.cli.net;
17 +
18 +import java.util.Collection;
19 +import java.util.Optional;
20 +
21 +import org.apache.karaf.shell.commands.Argument;
22 +import org.apache.karaf.shell.commands.Command;
23 +import org.onlab.packet.IpAddress;
24 +import org.onosproject.cli.AbstractShellCommand;
25 +import org.onosproject.core.ApplicationId;
26 +import org.onosproject.core.DefaultApplicationId;
27 +import org.onosproject.net.DeviceId;
28 +import org.onosproject.net.PortNumber;
29 +import org.onosproject.net.provider.ProviderId;
30 +import org.onosproject.net.tunnel.DefaultOpticalTunnelEndPoint;
31 +import org.onosproject.net.tunnel.IpTunnelEndPoint;
32 +import org.onosproject.net.tunnel.OpticalLogicId;
33 +import org.onosproject.net.tunnel.OpticalTunnelEndPoint;
34 +import org.onosproject.net.tunnel.Tunnel;
35 +import org.onosproject.net.tunnel.TunnelEndPoint;
36 +import org.onosproject.net.tunnel.TunnelService;
37 +
38 +/**
39 + * Borrows all tunnels between specific source tunnel end point and specific
40 + * destination tunnel end point. Supports for IP address and optical as tunnel end point now. It's used by consumers.
41 + */
42 +@Command(scope = "onos", name = "borrow-tunnels",
43 +description = "Borrows all tunnels between specific source tunnel end point"
44 + + " and specific destination tunnel end point."
45 + + " Supports for IP address and optical as tunnel end point now. It's used by consumers.")
46 +public class BorrowTunnelCommand extends AbstractShellCommand {
47 + @Argument(index = 0, name = "consumerId", description = "consumer id means application id.",
48 + required = true, multiValued = false)
49 + String consumerId = null;
50 + @Argument(index = 1, name = "src", description = "Source tunnel point."
51 + + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
52 + + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
53 + + " Otherwise src means IP address.", required = true, multiValued = false)
54 + String src = null;
55 + @Argument(index = 2, name = "dst", description = "Destination tunnel point."
56 + + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
57 + + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
58 + + " Otherwise dst means IP address.", required = true, multiValued = false)
59 + String dst = null;
60 +
61 + @Argument(index = 3, name = "type", description = "The type of tunnels,"
62 + + " It includes MPLS, VLAN, VXLAN, GRE, ODUK, OCH", required = true, multiValued = false)
63 + String type = null;
64 + private static final String FMT = "src=%s, dst=%s,"
65 + + "type=%s, state=%s, producerName=%s, tunnelName=%s,"
66 + + "groupId=%s";
67 +
68 + @Override
69 + protected void execute() {
70 + TunnelService service = get(TunnelService.class);
71 + ApplicationId appId = new DefaultApplicationId(1, consumerId);
72 + ProviderId producerName = new ProviderId("default",
73 + "org.onosproject.provider.tunnel.default");
74 + TunnelEndPoint srcPoint = null;
75 + TunnelEndPoint dstPoint = null;
76 + if ("MPLS".equals(type) || "VLAN".equals(type) || "VXLAN".equals(type)
77 + || "GRE".equals(type)) {
78 + srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
79 + dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
80 + } else if ("ODUK".equals(type) || "OCH".equals(type)) {
81 + String[] srcArray = src.split("-");
82 + String[] dstArray = dst.split("-");
83 + srcPoint = new DefaultOpticalTunnelEndPoint(
84 + producerName,
85 + Optional.of(DeviceId
86 + .deviceId(srcArray[0])),
87 + Optional.of(PortNumber
88 + .portNumber(srcArray[1])),
89 + null,
90 + OpticalTunnelEndPoint.Type.LAMBDA,
91 + OpticalLogicId
92 + .logicId(0),
93 + true);
94 + dstPoint = new DefaultOpticalTunnelEndPoint(
95 + producerName,
96 + Optional.of(DeviceId
97 + .deviceId(dstArray[0])),
98 + Optional.of(PortNumber
99 + .portNumber(dstArray[1])),
100 + null,
101 + OpticalTunnelEndPoint.Type.LAMBDA,
102 + OpticalLogicId
103 + .logicId(0),
104 + true);
105 + } else {
106 + print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
107 + return;
108 + }
109 + Collection<Tunnel> tunnelSet = service.borrowTunnel(appId, srcPoint, dstPoint);
110 + for (Tunnel tunnel : tunnelSet) {
111 + print(FMT, tunnel.src(), tunnel.dst(), tunnel.type(),
112 + tunnel.state(), tunnel.providerId(), tunnel.tunnelName(),
113 + tunnel.groupId());
114 + }
115 + }
116 +
117 +}
1 +/*
2 + * Copyright 2014-2015 Open Networking Laboratory
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 + */
16 +package org.onosproject.cli.net;
17 +
18 +import java.util.Optional;
19 +
20 +import org.apache.karaf.shell.commands.Argument;
21 +import org.apache.karaf.shell.commands.Command;
22 +import org.onlab.packet.IpAddress;
23 +import org.onosproject.cli.AbstractShellCommand;
24 +import org.onosproject.net.DeviceId;
25 +import org.onosproject.net.PortNumber;
26 +import org.onosproject.net.provider.ProviderId;
27 +import org.onosproject.net.tunnel.DefaultOpticalTunnelEndPoint;
28 +import org.onosproject.net.tunnel.IpTunnelEndPoint;
29 +import org.onosproject.net.tunnel.OpticalLogicId;
30 +import org.onosproject.net.tunnel.OpticalTunnelEndPoint;
31 +import org.onosproject.net.tunnel.TunnelAdminService;
32 +import org.onosproject.net.tunnel.TunnelEndPoint;
33 +
34 +/**
35 + * Supports for deleting all tunnels by using IP address and optical as tunnel
36 + * end point now. It's used by consumers.
37 + */
38 +@Command(scope = "onos", name = "delete-tunnels", description = "Supports for deleting all tunnels by using IP address"
39 + + " and optical as tunnel end point now. It's used by consumers.")
40 +public class DeleteTunnelCommand extends AbstractShellCommand {
41 + static String applicationId = "DEFAULT_APP_ID";
42 + @Argument(index = 0, name = "src", description = "Source tunnel point."
43 + + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
44 + + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
45 + + " Otherwise src means IP address.", required = true, multiValued = false)
46 + String src = null;
47 + @Argument(index = 1, name = "dst", description = "Destination tunnel point."
48 + + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
49 + + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
50 + + " Otherwise dst means IP address.", required = true, multiValued = false)
51 + String dst = null;
52 +
53 + @Argument(index = 2, name = "type", description = "The type of tunnels,"
54 + + " It includes MPLS, VLAN, VXLAN, GRE, ODUK, OCH", required = true, multiValued = false)
55 + String type = null;
56 +
57 + @Override
58 + protected void execute() {
59 + TunnelAdminService adminService = get(TunnelAdminService.class);
60 + ProviderId producerName = new ProviderId("default",
61 + "org.onosproject.provider.tunnel.default");
62 + TunnelEndPoint srcPoint = null;
63 + TunnelEndPoint dstPoint = null;
64 + if ("MPLS".equals(type) || "VLAN".equals(type) || "VXLAN".equals(type) || "GRE".equals(type)) {
65 + srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
66 + dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
67 + } else if ("ODUK".equals(type) || "OCH".equals(type)) {
68 + String[] srcArray = src.split("-");
69 + String[] dstArray = dst.split("-");
70 + srcPoint = new DefaultOpticalTunnelEndPoint(
71 + producerName,
72 + Optional.of(DeviceId
73 + .deviceId(srcArray[0])),
74 + Optional.of(PortNumber
75 + .portNumber(srcArray[1])),
76 + null,
77 + OpticalTunnelEndPoint.Type.LAMBDA,
78 + OpticalLogicId
79 + .logicId(0),
80 + true);
81 + dstPoint = new DefaultOpticalTunnelEndPoint(
82 + producerName,
83 + Optional.of(DeviceId
84 + .deviceId(dstArray[0])),
85 + Optional.of(PortNumber
86 + .portNumber(dstArray[1])),
87 + null,
88 + OpticalTunnelEndPoint.Type.LAMBDA,
89 + OpticalLogicId
90 + .logicId(0),
91 + true);
92 + } else {
93 + print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
94 + return;
95 + }
96 +
97 + adminService.removeTunnels(srcPoint, dstPoint, producerName);
98 + }
99 +
100 +}
1 +/*
2 + * Copyright 2014-2015 Open Networking Laboratory
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 + */
16 +package org.onosproject.cli.net;
17 +
18 +import java.util.Collection;
19 +import java.util.Optional;
20 +
21 +import org.apache.karaf.shell.commands.Argument;
22 +import org.apache.karaf.shell.commands.Command;
23 +import org.onlab.packet.IpAddress;
24 +import org.onosproject.cli.AbstractShellCommand;
25 +import org.onosproject.net.DeviceId;
26 +import org.onosproject.net.PortNumber;
27 +import org.onosproject.net.provider.ProviderId;
28 +import org.onosproject.net.tunnel.DefaultOpticalTunnelEndPoint;
29 +import org.onosproject.net.tunnel.IpTunnelEndPoint;
30 +import org.onosproject.net.tunnel.OpticalLogicId;
31 +import org.onosproject.net.tunnel.OpticalTunnelEndPoint;
32 +import org.onosproject.net.tunnel.Tunnel;
33 +import org.onosproject.net.tunnel.TunnelEndPoint;
34 +import org.onosproject.net.tunnel.TunnelService;
35 +
36 +/**
37 + * Supports for querying all tunnels by using IP address and optical as tunnel
38 + * end point now. It's used by consumers.
39 + */
40 +@Command(scope = "onos", name = "query-tunnels", description = "Supports for querying all tunnels by using IP address"
41 + + " and optical as tunnel end point now."
42 + + " It's used by consumers.")
43 +public class QueryTunnelCommand extends AbstractShellCommand {
44 + @Argument(index = 0, name = "src", description = "Source tunnel point."
45 + + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
46 + + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
47 + + " Otherwise src means IP address.", required = true, multiValued = false)
48 + String src = null;
49 + @Argument(index = 1, name = "dst", description = "Destination tunnel point."
50 + + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
51 + + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
52 + + " Otherwise dst means IP address.", required = true, multiValued = false)
53 + String dst = null;
54 +
55 + @Argument(index = 2, name = "type", description = "The type of tunnels,"
56 + + " It includes MPLS, VLAN, VXLAN, GRE, ODUK, OCH", required = true, multiValued = false)
57 + String type = null;
58 +
59 + private static final String FMT = "src=%s, dst=%s,"
60 + + "type=%s, state=%s, producerName=%s, tunnelName=%s,"
61 + + "groupId=%s";
62 +
63 + @Override
64 + protected void execute() {
65 + TunnelService service = get(TunnelService.class);
66 + ProviderId producerName = new ProviderId("default",
67 + "org.onosproject.provider.tunnel.default");
68 + TunnelEndPoint srcPoint = null;
69 + TunnelEndPoint dstPoint = null;
70 + if ("MPLS".equals(type) || "VLAN".equals(type) || "VXLAN".equals(type)
71 + || "GRE".equals(type)) {
72 + srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
73 + dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
74 + } else if ("ODUK".equals(type) || "OCH".equals(type)) {
75 + String[] srcArray = src.split("-");
76 + String[] dstArray = dst.split("-");
77 + srcPoint = new DefaultOpticalTunnelEndPoint(
78 + producerName,
79 + Optional.of(DeviceId
80 + .deviceId(srcArray[0])),
81 + Optional.of(PortNumber
82 + .portNumber(srcArray[1])),
83 + null,
84 + OpticalTunnelEndPoint.Type.LAMBDA,
85 + OpticalLogicId
86 + .logicId(0),
87 + true);
88 + dstPoint = new DefaultOpticalTunnelEndPoint(
89 + producerName,
90 + Optional.of(DeviceId
91 + .deviceId(dstArray[0])),
92 + Optional.of(PortNumber
93 + .portNumber(dstArray[1])),
94 + null,
95 + OpticalTunnelEndPoint.Type.LAMBDA,
96 + OpticalLogicId
97 + .logicId(0),
98 + true);
99 + } else {
100 + print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
101 + return;
102 + }
103 + Collection<Tunnel> tunnelSet = service.queryTunnel(srcPoint, dstPoint);
104 + for (Tunnel tunnel : tunnelSet) {
105 + print(FMT, tunnel.src().toString(), tunnel.dst().toString(), tunnel.type(),
106 + tunnel.state(), tunnel.providerId(), tunnel.tunnelName(),
107 + tunnel.groupId());
108 + }
109 + }
110 +
111 +}
1 +/*
2 + * Copyright 2014-2015 Open Networking Laboratory
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 + */
16 +package org.onosproject.cli.net;
17 +
18 +import java.util.Collection;
19 +
20 +import org.apache.karaf.shell.commands.Argument;
21 +import org.apache.karaf.shell.commands.Command;
22 +import org.onosproject.cli.AbstractShellCommand;
23 +import org.onosproject.core.ApplicationId;
24 +import org.onosproject.core.DefaultApplicationId;
25 +import org.onosproject.net.tunnel.TunnelService;
26 +import org.onosproject.net.tunnel.TunnelSubscription;
27 +
28 +/**
29 + * Query all tunnel subscriptions of consumer by consumer id.
30 + * It's used by consumers.
31 + */
32 +@Command(scope = "onos", name = "query-tunnel-subscriptions",
33 + description = "Query all request orders of consumer by consumer id. It's used by consumers.")
34 +public class QueryTunnelSubscriptionCommand extends AbstractShellCommand {
35 + @Argument(index = 0, name = "consumerId",
36 + description = "consumer id means provider id",
37 + required = true, multiValued = false)
38 + String consumerId = null;
39 + private static final String FMT = "appId=%s, src=%s, dst=%s,"
40 + + "type=%s, tunnelId=%s";
41 +
42 + @Override
43 + protected void execute() {
44 + TunnelService service = get(TunnelService.class);
45 + ApplicationId applicationId = new DefaultApplicationId(1, consumerId);
46 + Collection<TunnelSubscription> tunnelSet = service.queryTunnelSubscription(applicationId);
47 + for (TunnelSubscription order : tunnelSet) {
48 + print(FMT, order.consumerId(), order.src(), order.dst(),
49 + order.type(), order.tunnelId());
50 + }
51 + }
52 +
53 +}
1 +/*
2 + * Copyright 2014-2015 Open Networking Laboratory
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 + */
16 +package org.onosproject.cli.net;
17 +
18 +import java.util.Optional;
19 +
20 +import org.apache.karaf.shell.commands.Argument;
21 +import org.apache.karaf.shell.commands.Command;
22 +import org.onlab.packet.IpAddress;
23 +import org.onosproject.cli.AbstractShellCommand;
24 +import org.onosproject.core.ApplicationId;
25 +import org.onosproject.core.DefaultApplicationId;
26 +import org.onosproject.net.DeviceId;
27 +import org.onosproject.net.PortNumber;
28 +import org.onosproject.net.provider.ProviderId;
29 +import org.onosproject.net.tunnel.DefaultOpticalTunnelEndPoint;
30 +import org.onosproject.net.tunnel.IpTunnelEndPoint;
31 +import org.onosproject.net.tunnel.OpticalLogicId;
32 +import org.onosproject.net.tunnel.OpticalTunnelEndPoint;
33 +import org.onosproject.net.tunnel.TunnelEndPoint;
34 +import org.onosproject.net.tunnel.TunnelService;
35 +
36 +/**
37 + * Returns all tunnels between specific source tunnel end point and specific
38 + * destination tunnel end point. Supports for IP address and optical as tunnel
39 + * end point now. It's used by consumers.
40 + */
41 +@Command(scope = "onos", name = "return-tunnels",
42 +description = "Returns all tunnels between specific source tunnel end point and specific "
43 + + " destination tunnel end point. Supports for IP address and optical as tunnel end point now."
44 + + " It's used by consumers.")
45 +public class ReturnTunnelCommand extends AbstractShellCommand {
46 + @Argument(index = 0, name = "consumerId", description = "consumer id means application id.",
47 + required = true, multiValued = false)
48 + String consumerId = null;
49 + @Argument(index = 1, name = "src", description = "Source tunnel point."
50 + + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
51 + + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
52 + + " Otherwise src means IP address.", required = true, multiValued = false)
53 + String src = null;
54 + @Argument(index = 2, name = "dst", description = "Destination tunnel point."
55 + + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
56 + + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
57 + + " Otherwise dst means IP address.", required = true, multiValued = false)
58 + String dst = null;
59 +
60 + @Argument(index = 3, name = "type", description = "The type of tunnels,"
61 + + " It includes MPLS, VLAN, VXLAN, GRE, ODUK, OCH", required = true, multiValued = false)
62 + String type = null;
63 +
64 + @Override
65 + protected void execute() {
66 + TunnelService service = get(TunnelService.class);
67 + ApplicationId appId = new DefaultApplicationId(1, consumerId);
68 + ProviderId producerName = new ProviderId("default",
69 + "org.onosproject.provider.tunnel.default");
70 + TunnelEndPoint srcPoint = null;
71 + TunnelEndPoint dstPoint = null;
72 + if ("MPLS".equals(type) || "VLAN".equals(type) || "VXLAN".equals(type)
73 + || "GRE".equals(type)) {
74 + srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
75 + dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
76 + } else if ("ODUK".equals(type) || "OCH".equals(type)) {
77 + String[] srcArray = src.split("-");
78 + String[] dstArray = dst.split("-");
79 + srcPoint = new DefaultOpticalTunnelEndPoint(
80 + producerName,
81 + Optional.of(DeviceId
82 + .deviceId(srcArray[0])),
83 + Optional.of(PortNumber
84 + .portNumber(srcArray[1])),
85 + null,
86 + OpticalTunnelEndPoint.Type.LAMBDA,
87 + OpticalLogicId
88 + .logicId(0),
89 + true);
90 + dstPoint = new DefaultOpticalTunnelEndPoint(
91 + producerName,
92 + Optional.of(DeviceId
93 + .deviceId(dstArray[0])),
94 + Optional.of(PortNumber
95 + .portNumber(dstArray[1])),
96 + null,
97 + OpticalTunnelEndPoint.Type.LAMBDA,
98 + OpticalLogicId
99 + .logicId(0),
100 + true);
101 + } else {
102 + print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
103 + return;
104 + }
105 + service.returnTunnel(appId, srcPoint, dstPoint);
106 + }
107 +
108 +}
...@@ -367,6 +367,22 @@ ...@@ -367,6 +367,22 @@
367 <command> 367 <command>
368 <action class="org.onosproject.cli.net.ApplyLabelResourceCommand"/> 368 <action class="org.onosproject.cli.net.ApplyLabelResourceCommand"/>
369 </command> 369 </command>
370 + <!-- tunnel commands -->
371 + <command>
372 + <action class="org.onosproject.cli.net.DeleteTunnelCommand"/>
373 + </command>
374 + <command>
375 + <action class="org.onosproject.cli.net.BorrowTunnelCommand"/>
376 + </command>
377 + <command>
378 + <action class="org.onosproject.cli.net.ReturnTunnelCommand"/>
379 + </command>
380 + <command>
381 + <action class="org.onosproject.cli.net.QueryTunnelCommand"/>
382 + </command>
383 + <command>
384 + <action class="org.onosproject.cli.net.QueryTunnelSubscriptionCommand"/>
385 + </command>
370 </command-bundle> 386 </command-bundle>
371 387
372 <bean id="permAppNameCompleter" class="org.onosproject.cli.security.PermissionApplicationNameCompleter"/> 388 <bean id="permAppNameCompleter" class="org.onosproject.cli.security.PermissionApplicationNameCompleter"/>
......
...@@ -15,11 +15,11 @@ ...@@ -15,11 +15,11 @@
15 */ 15 */
16 package org.onosproject.net.tunnel.impl; 16 package org.onosproject.net.tunnel.impl;
17 17
18 +import static com.google.common.base.Preconditions.checkNotNull;
18 import static org.slf4j.LoggerFactory.getLogger; 19 import static org.slf4j.LoggerFactory.getLogger;
19 20
20 import java.util.Collection; 21 import java.util.Collection;
21 import java.util.Set; 22 import java.util.Set;
22 -import java.util.concurrent.ExecutorService;
23 23
24 import org.apache.felix.scr.annotations.Activate; 24 import org.apache.felix.scr.annotations.Activate;
25 import org.apache.felix.scr.annotations.Component; 25 import org.apache.felix.scr.annotations.Component;
...@@ -28,16 +28,14 @@ import org.apache.felix.scr.annotations.Reference; ...@@ -28,16 +28,14 @@ import org.apache.felix.scr.annotations.Reference;
28 import org.apache.felix.scr.annotations.ReferenceCardinality; 28 import org.apache.felix.scr.annotations.ReferenceCardinality;
29 import org.apache.felix.scr.annotations.Service; 29 import org.apache.felix.scr.annotations.Service;
30 import org.onosproject.core.ApplicationId; 30 import org.onosproject.core.ApplicationId;
31 -import org.onosproject.core.CoreService;
32 import org.onosproject.event.EventDeliveryService; 31 import org.onosproject.event.EventDeliveryService;
33 import org.onosproject.event.ListenerRegistry; 32 import org.onosproject.event.ListenerRegistry;
34 import org.onosproject.net.Annotations; 33 import org.onosproject.net.Annotations;
35 import org.onosproject.net.Path; 34 import org.onosproject.net.Path;
36 -import org.onosproject.net.link.LinkEvent;
37 -import org.onosproject.net.link.LinkListener;
38 import org.onosproject.net.provider.AbstractProviderRegistry; 35 import org.onosproject.net.provider.AbstractProviderRegistry;
39 import org.onosproject.net.provider.AbstractProviderService; 36 import org.onosproject.net.provider.AbstractProviderService;
40 import org.onosproject.net.provider.ProviderId; 37 import org.onosproject.net.provider.ProviderId;
38 +import org.onosproject.net.tunnel.DefaultTunnel;
41 import org.onosproject.net.tunnel.Tunnel; 39 import org.onosproject.net.tunnel.Tunnel;
42 import org.onosproject.net.tunnel.Tunnel.Type; 40 import org.onosproject.net.tunnel.Tunnel.Type;
43 import org.onosproject.net.tunnel.TunnelAdminService; 41 import org.onosproject.net.tunnel.TunnelAdminService;
...@@ -73,8 +71,7 @@ public class TunnelManager ...@@ -73,8 +71,7 @@ public class TunnelManager
73 listenerRegistry = new ListenerRegistry<>(); 71 listenerRegistry = new ListenerRegistry<>();
74 72
75 private final TunnelStoreDelegate delegate = new InternalStoreDelegate(); 73 private final TunnelStoreDelegate delegate = new InternalStoreDelegate();
76 - private final InternalTunnelListener tunnelListener = new InternalTunnelListener(); 74 +
77 - private InternalLinkListener linkListener = new InternalLinkListener();
78 75
79 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 76 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
80 protected TunnelStore store; 77 protected TunnelStore store;
...@@ -82,229 +79,279 @@ public class TunnelManager ...@@ -82,229 +79,279 @@ public class TunnelManager
82 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) 79 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
83 protected EventDeliveryService eventDispatcher; 80 protected EventDeliveryService eventDispatcher;
84 81
85 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
86 - protected CoreService coreService;
87 -
88 - private ExecutorService futureService;
89 -
90 @Activate 82 @Activate
91 public void activate() { 83 public void activate() {
92 - // TODO Auto-generated method stub 84 + store.setDelegate(delegate);
85 + eventDispatcher.addSink(TunnelEvent.class, listenerRegistry);
93 log.info("Started"); 86 log.info("Started");
94 } 87 }
95 88
96 @Deactivate 89 @Deactivate
97 public void deactivate() { 90 public void deactivate() {
98 - // TODO Auto-generated method stub 91 + store.unsetDelegate(delegate);
92 + eventDispatcher.removeSink(TunnelEvent.class);
99 log.info("Stopped"); 93 log.info("Stopped");
100 } 94 }
101 95
102 @Override 96 @Override
103 - protected TunnelProviderService createProviderService(TunnelProvider provider) { 97 + public void removeTunnel(TunnelId tunnelId) {
104 - // TODO Auto-generated method stub 98 + checkNotNull(tunnelId, TUNNNEL_ID_NULL);
105 - return new InternalTunnelProviderService(provider); 99 + store.deleteTunnel(tunnelId);
106 - } 100 + Tunnel tunnel = store.queryTunnel(tunnelId);
107 - 101 + if (tunnel.providerId() != null) {
108 - @Override 102 + TunnelProvider provider = getProvider(tunnel.providerId());
109 - public TunnelProviderService register(TunnelProvider provider) { 103 + if (provider != null) {
110 - // TODO Auto-generated method stub 104 + provider.releaseTunnel(tunnel);
111 - return null; 105 + }
112 - } 106 + } else {
113 - 107 + Set<ProviderId> ids = getProviders();
114 - @Override 108 + for (ProviderId providerId : ids) {
115 - public void unregister(TunnelProvider provider) { 109 + TunnelProvider provider = getProvider(providerId);
116 - // TODO Auto-generated method stub 110 + provider.releaseTunnel(tunnel);
117 -
118 - }
119 -
120 - @Override
121 - public Set<ProviderId> getProviders() {
122 - // TODO Auto-generated method stub
123 - return null;
124 - }
125 -
126 - @Override
127 - public void addListener(TunnelListener listener) {
128 - // TODO Auto-generated method stub
129 -
130 - }
131 -
132 - @Override
133 - public void removeListener(TunnelListener listener) {
134 - // TODO Auto-generated method stub
135 -
136 - }
137 -
138 - private class InternalTunnelListener implements TunnelListener {
139 - @Override
140 - public void event(TunnelEvent event) {
141 - // TODO Auto-generated method stub
142 -
143 - }
144 - }
145 -
146 - private class InternalLinkListener implements LinkListener {
147 - @Override
148 - public void event(LinkEvent event) {
149 - // TODO Auto-generated method stub
150 -
151 - }
152 - }
153 -
154 - private class InternalTunnelProviderService
155 - extends AbstractProviderService<TunnelProvider>
156 - implements TunnelProviderService {
157 - protected InternalTunnelProviderService(TunnelProvider provider) {
158 - super(provider);
159 - // TODO Auto-generated constructor stub
160 - }
161 -
162 - @Override
163 - public TunnelId tunnelAdded(TunnelDescription tunnel) {
164 - // TODO Auto-generated method stub
165 - return null;
166 - }
167 -
168 - @Override
169 - public void tunnelUpdated(TunnelDescription tunnel) {
170 - // TODO Auto-generated method stub
171 -
172 - }
173 -
174 - @Override
175 - public void tunnelRemoved(TunnelDescription tunnel) {
176 - // TODO Auto-generated method stub
177 -
178 - }
179 -
180 - }
181 -
182 - private class InternalStoreDelegate implements TunnelStoreDelegate {
183 - @Override
184 - public void notify(TunnelEvent event) {
185 - // TODO Auto-generated method stub
186 - if (event != null) {
187 - eventDispatcher.post(event);
188 } 111 }
189 } 112 }
190 } 113 }
191 114
192 @Override 115 @Override
193 - public void removeTunnel(TunnelId tunnelId) { 116 + public void updateTunnel(Tunnel tunnel, Path path) {
194 - // TODO Auto-generated method stub 117 + store.createOrUpdateTunnel(tunnel);
195 - 118 + if (tunnel.providerId() != null) {
119 + TunnelProvider provider = getProvider(tunnel.providerId());
120 + if (provider != null) {
121 + provider.updateTunnel(tunnel, path);
122 + }
123 + } else {
124 + Set<ProviderId> ids = getProviders();
125 + for (ProviderId providerId : ids) {
126 + TunnelProvider provider = getProvider(providerId);
127 + provider.updateTunnel(tunnel, path);
128 + }
129 + }
196 } 130 }
197 131
198 @Override 132 @Override
199 public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, 133 public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst,
200 ProviderId producerName) { 134 ProviderId producerName) {
201 - // TODO Auto-generated method stub 135 + store.deleteTunnel(src, dst, producerName);
202 - 136 + Collection<Tunnel> setTunnels = store.queryTunnel(src, dst);
203 - } 137 + for (Tunnel tunnel : setTunnels) {
204 - 138 + if (producerName != null
205 - @Override 139 + && !tunnel.providerId().equals(producerName)) {
206 - public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, 140 + continue;
207 - Type type, ProviderId producerName) { 141 + }
208 - // TODO Auto-generated method stub 142 + if (tunnel.providerId() != null) {
209 - 143 + TunnelProvider provider = getProvider(tunnel.providerId());
144 + if (provider != null) {
145 + provider.releaseTunnel(tunnel);
146 + }
147 + } else {
148 + Set<ProviderId> ids = getProviders();
149 + for (ProviderId providerId : ids) {
150 + TunnelProvider provider = getProvider(providerId);
151 + provider.releaseTunnel(tunnel);
152 + }
153 + }
154 + }
210 } 155 }
211 156
212 @Override 157 @Override
213 - public void updateTunnel(Tunnel tunnel, Path path) { 158 + public void removeTunnels(TunnelEndPoint src, TunnelEndPoint dst, Type type,
214 - // TODO Auto-generated method stub 159 + ProviderId producerName) {
215 - 160 + store.deleteTunnel(src, dst, type, producerName);
161 + Collection<Tunnel> setTunnels = store.queryTunnel(src, dst);
162 + for (Tunnel tunnel : setTunnels) {
163 + if (producerName != null
164 + && !tunnel.providerId().equals(producerName)
165 + || !type.equals(tunnel.type())) {
166 + continue;
167 + }
168 + if (tunnel.providerId() != null) {
169 + TunnelProvider provider = getProvider(tunnel.providerId());
170 + if (provider != null) {
171 + provider.releaseTunnel(tunnel);
172 + }
173 + } else {
174 + Set<ProviderId> ids = getProviders();
175 + for (ProviderId providerId : ids) {
176 + TunnelProvider provider = getProvider(providerId);
177 + provider.releaseTunnel(tunnel);
178 + }
179 + }
180 + }
216 } 181 }
217 182
218 @Override 183 @Override
219 public Tunnel borrowTunnel(ApplicationId consumerId, TunnelId tunnelId, 184 public Tunnel borrowTunnel(ApplicationId consumerId, TunnelId tunnelId,
220 - Annotations... annotations) { 185 + Annotations... annotations) {
221 - // TODO Auto-generated method stub 186 + return store.borrowTunnel(consumerId, tunnelId, annotations);
222 - return null;
223 } 187 }
224 188
225 @Override 189 @Override
226 public Collection<Tunnel> borrowTunnel(ApplicationId consumerId, 190 public Collection<Tunnel> borrowTunnel(ApplicationId consumerId,
227 - TunnelName tunnelName, 191 + TunnelName tunnelName,
228 - Annotations... annotations) { 192 + Annotations... annotations) {
229 - // TODO Auto-generated method stub 193 + return store.borrowTunnel(consumerId, tunnelName, annotations);
230 - return null;
231 } 194 }
232 195
233 @Override 196 @Override
234 public Collection<Tunnel> borrowTunnel(ApplicationId consumerId, 197 public Collection<Tunnel> borrowTunnel(ApplicationId consumerId,
235 - TunnelEndPoint src, 198 + TunnelEndPoint src, TunnelEndPoint dst,
236 - TunnelEndPoint dst, 199 + Annotations... annotations) {
237 - Annotations... annotations) { 200 + Collection<Tunnel> tunnels = store.borrowTunnel(consumerId, src,
238 - // TODO Auto-generated method stub 201 + dst, annotations);
239 - return null; 202 + if (tunnels == null || tunnels.size() == 0) {
203 + Tunnel tunnel = new DefaultTunnel(null, src, dst, null, null, null,
204 + null, null, annotations);
205 + Set<ProviderId> ids = getProviders();
206 + for (ProviderId providerId : ids) {
207 + TunnelProvider provider = getProvider(providerId);
208 + provider.setupTunnel(tunnel, null);
209 + }
210 + }
211 + return tunnels;
240 } 212 }
241 213
242 @Override 214 @Override
243 public Collection<Tunnel> borrowTunnel(ApplicationId consumerId, 215 public Collection<Tunnel> borrowTunnel(ApplicationId consumerId,
244 - TunnelEndPoint src, 216 + TunnelEndPoint src, TunnelEndPoint dst,
245 - TunnelEndPoint dst, Type type, 217 + Type type, Annotations... annotations) {
246 - Annotations... annotations) { 218 + Collection<Tunnel> tunnels = store.borrowTunnel(consumerId, src,
247 - // TODO Auto-generated method stub 219 + dst, type,
248 - return null; 220 + annotations);
221 + if (tunnels == null || tunnels.size() == 0) {
222 + Tunnel tunnel = new DefaultTunnel(null, src, dst, type, null, null,
223 + null, null, annotations);
224 + Set<ProviderId> ids = getProviders();
225 + for (ProviderId providerId : ids) {
226 + TunnelProvider provider = getProvider(providerId);
227 + provider.setupTunnel(tunnel, null);
228 + }
229 + }
230 + return tunnels;
249 } 231 }
250 232
251 @Override 233 @Override
252 - public boolean returnTunnel(ApplicationId consumerId, TunnelId tunnelId, 234 + public boolean returnTunnel(ApplicationId consumerId,
253 - Annotations... annotations) { 235 + TunnelId tunnelId, Annotations... annotations) {
254 - // TODO Auto-generated method stub 236 + return store.returnTunnel(consumerId, tunnelId, annotations);
255 - return false;
256 } 237 }
257 238
258 @Override 239 @Override
259 public boolean returnTunnel(ApplicationId consumerId, 240 public boolean returnTunnel(ApplicationId consumerId,
260 - TunnelName tunnelName, Annotations... annotations) { 241 + TunnelName tunnelName,
261 - // TODO Auto-generated method stub 242 + Annotations... annotations) {
262 - return false; 243 + return store.returnTunnel(consumerId, tunnelName, annotations);
263 } 244 }
264 245
265 @Override 246 @Override
266 public boolean returnTunnel(ApplicationId consumerId, TunnelEndPoint src, 247 public boolean returnTunnel(ApplicationId consumerId, TunnelEndPoint src,
267 - TunnelEndPoint dst, Type type, 248 + TunnelEndPoint dst, Type type,
268 - Annotations... annotations) { 249 + Annotations... annotations) {
269 - // TODO Auto-generated method stub 250 + return store.returnTunnel(consumerId, src, dst, type, annotations);
270 - return false;
271 } 251 }
272 252
273 @Override 253 @Override
274 public boolean returnTunnel(ApplicationId consumerId, TunnelEndPoint src, 254 public boolean returnTunnel(ApplicationId consumerId, TunnelEndPoint src,
275 - TunnelEndPoint dst, Annotations... annotations) { 255 + TunnelEndPoint dst, Annotations... annotations) {
276 - // TODO Auto-generated method stub 256 + return store.returnTunnel(consumerId, src, dst, annotations);
277 - return false;
278 } 257 }
279 258
280 @Override 259 @Override
281 public Tunnel queryTunnel(TunnelId tunnelId) { 260 public Tunnel queryTunnel(TunnelId tunnelId) {
282 - // TODO Auto-generated method stub 261 + return store.queryTunnel(tunnelId);
283 - return null;
284 } 262 }
285 263
286 @Override 264 @Override
287 public Collection<TunnelSubscription> queryTunnelSubscription(ApplicationId consumerId) { 265 public Collection<TunnelSubscription> queryTunnelSubscription(ApplicationId consumerId) {
288 - // TODO Auto-generated method stub 266 + return store.queryTunnelSubscription(consumerId);
289 - return null;
290 } 267 }
291 268
292 @Override 269 @Override
293 public Collection<Tunnel> queryTunnel(Type type) { 270 public Collection<Tunnel> queryTunnel(Type type) {
294 - // TODO Auto-generated method stub 271 + return store.queryTunnel(type);
295 - return null;
296 } 272 }
297 273
298 @Override 274 @Override
299 public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) { 275 public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
300 - // TODO Auto-generated method stub 276 + return store.queryTunnel(src, dst);
301 - return null;
302 } 277 }
303 278
304 @Override 279 @Override
305 public int tunnelCount() { 280 public int tunnelCount() {
306 - // TODO Auto-generated method stub 281 + return store.tunnelCount();
307 - return 0; 282 + }
283 +
284 + @Override
285 + protected TunnelProviderService createProviderService(TunnelProvider provider) {
286 + return new InternalTunnelProviderService(provider);
287 + }
288 +
289 + @Override
290 + public void addListener(TunnelListener listener) {
291 + listenerRegistry.addListener(listener);
292 + }
293 +
294 + @Override
295 + public void removeListener(TunnelListener listener) {
296 + listenerRegistry.removeListener(listener);
308 } 297 }
309 298
299 + private class InternalTunnelProviderService
300 + extends AbstractProviderService<TunnelProvider>
301 + implements TunnelProviderService {
302 + protected InternalTunnelProviderService(TunnelProvider provider) {
303 + super(provider);
304 + }
305 +
306 +
307 + @Override
308 + public TunnelId tunnelAdded(TunnelDescription tunnel) {
309 + Tunnel storedTunnel = new DefaultTunnel(provider().id(),
310 + tunnel.src(), tunnel.dst(),
311 + tunnel.type(),
312 + tunnel.groupId(),
313 + tunnel.id(),
314 + tunnel.tunnelName(),
315 + tunnel.annotations());
316 + return store.createOrUpdateTunnel(storedTunnel);
317 + }
318 +
319 + @Override
320 + public void tunnelUpdated(TunnelDescription tunnel) {
321 + Tunnel storedTunnel = new DefaultTunnel(provider().id(),
322 + tunnel.src(), tunnel.dst(),
323 + tunnel.type(),
324 + tunnel.groupId(),
325 + tunnel.id(),
326 + tunnel.tunnelName(),
327 + tunnel.annotations());
328 + store.createOrUpdateTunnel(storedTunnel);
329 + }
330 +
331 + @Override
332 + public void tunnelRemoved(TunnelDescription tunnel) {
333 + if (tunnel.id() != null) {
334 + store.deleteTunnel(tunnel.id());
335 + }
336 + if (tunnel.src() != null && tunnel.dst() != null
337 + && tunnel.type() != null) {
338 + store.deleteTunnel(tunnel.src(), tunnel.dst(), tunnel.type(),
339 + provider().id());
340 + }
341 + if (tunnel.src() != null && tunnel.dst() != null
342 + && tunnel.type() == null) {
343 + store.deleteTunnel(tunnel.src(), tunnel.dst(), provider().id());
344 + }
345 + }
346 +
347 + }
348 +
349 + private class InternalStoreDelegate implements TunnelStoreDelegate {
350 + @Override
351 + public void notify(TunnelEvent event) {
352 + if (event != null) {
353 + eventDispatcher.post(event);
354 + }
355 + }
356 + }
310 } 357 }
......
1 +package org.onosproject.store.tunnel.impl;
2 +
3 +import static org.slf4j.LoggerFactory.getLogger;
4 +
5 +import java.util.ArrayList;
6 +import java.util.Collection;
7 +import java.util.Collections;
8 +import java.util.HashSet;
9 +import java.util.List;
10 +import java.util.Objects;
11 +import java.util.Set;
12 +
13 +import org.apache.felix.scr.annotations.Activate;
14 +import org.apache.felix.scr.annotations.Component;
15 +import org.apache.felix.scr.annotations.Deactivate;
16 +import org.apache.felix.scr.annotations.Reference;
17 +import org.apache.felix.scr.annotations.ReferenceCardinality;
18 +import org.apache.felix.scr.annotations.Service;
19 +import org.onlab.util.KryoNamespace;
20 +import org.onosproject.cluster.ClusterService;
21 +import org.onosproject.core.ApplicationId;
22 +import org.onosproject.core.CoreService;
23 +import org.onosproject.core.IdGenerator;
24 +import org.onosproject.net.Annotations;
25 +import org.onosproject.net.provider.ProviderId;
26 +import org.onosproject.net.tunnel.DefaultTunnel;
27 +import org.onosproject.net.tunnel.Tunnel;
28 +import org.onosproject.net.tunnel.Tunnel.Type;
29 +import org.onosproject.net.tunnel.TunnelEndPoint;
30 +import org.onosproject.net.tunnel.TunnelEvent;
31 +import org.onosproject.net.tunnel.TunnelId;
32 +import org.onosproject.net.tunnel.TunnelName;
33 +import org.onosproject.net.tunnel.TunnelStore;
34 +import org.onosproject.net.tunnel.TunnelStoreDelegate;
35 +import org.onosproject.net.tunnel.TunnelSubscription;
36 +import org.onosproject.store.AbstractStore;
37 +import org.onosproject.store.app.GossipApplicationStore.InternalState;
38 +import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
39 +import org.onosproject.store.serializers.KryoNamespaces;
40 +import org.onosproject.store.service.EventuallyConsistentMap;
41 +import org.onosproject.store.service.MultiValuedTimestamp;
42 +import org.onosproject.store.service.StorageService;
43 +import org.onosproject.store.service.WallclockClockManager;
44 +import org.slf4j.Logger;
45 +
46 +import com.google.common.base.MoreObjects;
47 +import com.google.common.collect.ImmutableSet;
48 +
49 +/**
50 + * Manages inventory of tunnel in distributed data store that uses optimistic
51 + * replication and gossip based techniques.
52 + */
53 +@Component(immediate = true)
54 +@Service
55 +public class DistributedTunnelStore
56 + extends AbstractStore<TunnelEvent, TunnelStoreDelegate>
57 + implements TunnelStore {
58 +
59 + private final Logger log = getLogger(getClass());
60 +
61 + /**
62 + * The topic used for obtaining globally unique ids.
63 + */
64 + private String runnelOpTopoic = "tunnel-ops-ids";
65 +
66 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
67 + protected ClusterCommunicationService clusterCommunicator;
68 +
69 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
70 + protected ClusterService clusterService;
71 +
72 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
73 + protected CoreService coreService;
74 +
75 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
76 + protected StorageService storageService;
77 +
78 + // tunnel identity as map key in the store.
79 + private EventuallyConsistentMap<TunnelId, Tunnel> tunnelIdAsKeyStore;
80 + // tunnel name as map key in the store.
81 + private EventuallyConsistentMap<TunnelName, Set<TunnelId>> tunnelNameAsKeyStore;
82 + // maintains all the tunnels between source and destination.
83 + private EventuallyConsistentMap<TunnelKey, Set<TunnelId>> srcAndDstKeyStore;
84 + // maintains all the tunnels by tunnel type.
85 + private EventuallyConsistentMap<Tunnel.Type, Set<TunnelId>> typeKeyStore;
86 + // maintains records that app subscribes tunnel.
87 + private EventuallyConsistentMap<ApplicationId, Set<TunnelSubscription>> orderRelationship;
88 +
89 + private IdGenerator idGenerator;
90 +
91 + @Activate
92 + public void activate() {
93 + KryoNamespace.Builder serializer = KryoNamespace.newBuilder()
94 + .register(KryoNamespaces.API)
95 + .register(MultiValuedTimestamp.class)
96 + .register(InternalState.class);
97 + tunnelIdAsKeyStore = storageService
98 + .<TunnelId, Tunnel>eventuallyConsistentMapBuilder()
99 + .withName("all_tunnel").withSerializer(serializer)
100 + .withClockService(new WallclockClockManager<>()).build();
101 + tunnelNameAsKeyStore = storageService
102 + .<TunnelName, Set<TunnelId>>eventuallyConsistentMapBuilder()
103 + .withName("tunnel_name_tunnel").withSerializer(serializer)
104 + .withClockService(new WallclockClockManager<>()).build();
105 + srcAndDstKeyStore = storageService
106 + .<TunnelKey, Set<TunnelId>>eventuallyConsistentMapBuilder()
107 + .withName("src_dst_tunnel").withSerializer(serializer)
108 + .withClockService(new WallclockClockManager<>()).build();
109 + typeKeyStore = storageService
110 + .<Tunnel.Type, Set<TunnelId>>eventuallyConsistentMapBuilder()
111 + .withName("type_tunnel").withSerializer(serializer)
112 + .withClockService(new WallclockClockManager<>()).build();
113 + idGenerator = coreService.getIdGenerator(runnelOpTopoic);
114 + log.info("Started");
115 + }
116 +
117 + @Deactivate
118 + public void deactivate() {
119 + tunnelIdAsKeyStore.destroy();
120 + srcAndDstKeyStore.destroy();
121 + typeKeyStore.destroy();
122 + tunnelNameAsKeyStore.destroy();
123 + log.info("Stopped");
124 + }
125 +
126 + @Override
127 + public TunnelId createOrUpdateTunnel(Tunnel tunnel) {
128 + // tunnelIdAsKeyStore.
129 + if (tunnel.tunnelId() != null && !"".equals(tunnel.tunnelId())) {
130 + Tunnel old = tunnelIdAsKeyStore.get(tunnel.tunnelId());
131 + if (old == null) {
132 + log.info("This tunnel[" + tunnel.tunnelId() + "] is not available.");
133 + return tunnel.tunnelId();
134 + }
135 + Tunnel newT = new DefaultTunnel(tunnel.providerId(), tunnel.src(),
136 + tunnel.dst(), tunnel.type(),
137 + tunnel.state(), tunnel.groupId(),
138 + old.tunnelId(),
139 + tunnel.tunnelName(),
140 + tunnel.annotations());
141 + tunnelIdAsKeyStore.remove(tunnel.tunnelId());
142 + tunnelIdAsKeyStore.put(tunnel.tunnelId(), newT);
143 + TunnelEvent event = new TunnelEvent(
144 + TunnelEvent.Type.TUNNEL_UPDATED,
145 + tunnel);
146 + notifyDelegate(event);
147 + return tunnel.tunnelId();
148 + } else {
149 + TunnelId tunnelId = TunnelId.valueOf(idGenerator.getNewId());
150 + Tunnel newT = new DefaultTunnel(tunnel.providerId(), tunnel.src(),
151 + tunnel.dst(), tunnel.type(),
152 + tunnel.state(), tunnel.groupId(),
153 + tunnelId,
154 + tunnel.tunnelName(),
155 + tunnel.annotations());
156 + TunnelKey key = TunnelKey.tunnelKey(tunnel.src(), tunnel.dst());
157 + tunnelIdAsKeyStore.put(tunnelId, newT);
158 + Set<TunnelId> tunnelnameSet = tunnelNameAsKeyStore.get(tunnel
159 + .tunnelName());
160 + if (tunnelnameSet == null) {
161 + tunnelnameSet = new HashSet<TunnelId>();
162 + }
163 + tunnelnameSet.add(tunnelId);
164 + tunnelNameAsKeyStore.put(tunnel
165 + .tunnelName(), tunnelnameSet);
166 + Set<TunnelId> srcAndDstKeySet = srcAndDstKeyStore.get(key);
167 + if (srcAndDstKeySet == null) {
168 + srcAndDstKeySet = new HashSet<TunnelId>();
169 + }
170 + srcAndDstKeySet.add(tunnelId);
171 + srcAndDstKeyStore.put(key, srcAndDstKeySet);
172 + Set<TunnelId> typeKeySet = typeKeyStore.get(tunnel.type());
173 + if (typeKeySet == null) {
174 + typeKeySet = new HashSet<TunnelId>();
175 + }
176 + typeKeySet.add(tunnelId);
177 + typeKeyStore.put(tunnel.type(), typeKeySet);
178 + TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_ADDED,
179 + tunnel);
180 + notifyDelegate(event);
181 + return tunnelId;
182 + }
183 + }
184 +
185 + @Override
186 + public void deleteTunnel(TunnelId tunnelId) {
187 + Tunnel deletedTunnel = tunnelIdAsKeyStore.get(tunnelId);
188 + if (deletedTunnel == null) {
189 + return;
190 + }
191 + tunnelNameAsKeyStore.get(deletedTunnel.tunnelName()).remove(tunnelId);
192 + tunnelIdAsKeyStore.remove(tunnelId);
193 + TunnelKey key = new TunnelKey(deletedTunnel.src(), deletedTunnel.dst());
194 + srcAndDstKeyStore.get(key).remove(tunnelId);
195 + typeKeyStore.get(deletedTunnel.type()).remove(tunnelId);
196 + TunnelEvent event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED,
197 + deletedTunnel);
198 + notifyDelegate(event);
199 + }
200 +
201 + @Override
202 + public void deleteTunnel(TunnelEndPoint src, TunnelEndPoint dst,
203 + ProviderId producerName) {
204 + TunnelKey key = TunnelKey.tunnelKey(src, dst);
205 + Set<TunnelId> idSet = srcAndDstKeyStore.get(key);
206 + if (idSet == null) {
207 + return;
208 + }
209 + Tunnel deletedTunnel = null;
210 + TunnelEvent event = null;
211 + List<TunnelEvent> ls = new ArrayList<TunnelEvent>();
212 + for (TunnelId id : idSet) {
213 + deletedTunnel = tunnelIdAsKeyStore.get(id);
214 + event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED,
215 + deletedTunnel);
216 + ls.add(event);
217 + if (producerName.equals(deletedTunnel.providerId())) {
218 + tunnelIdAsKeyStore.remove(deletedTunnel.tunnelId());
219 + tunnelNameAsKeyStore.get(deletedTunnel.tunnelName())
220 + .remove(deletedTunnel.tunnelId());
221 + srcAndDstKeyStore.get(key).remove(deletedTunnel.tunnelId());
222 + typeKeyStore.get(deletedTunnel.type())
223 + .remove(deletedTunnel.tunnelId());
224 + }
225 + }
226 + notifyDelegate(ls);
227 + }
228 +
229 + @Override
230 + public void deleteTunnel(TunnelEndPoint src, TunnelEndPoint dst, Type type,
231 + ProviderId producerName) {
232 + TunnelKey key = TunnelKey.tunnelKey(src, dst);
233 + Set<TunnelId> idSet = srcAndDstKeyStore.get(key);
234 + if (idSet == null) {
235 + return;
236 + }
237 + Tunnel deletedTunnel = null;
238 + TunnelEvent event = null;
239 + List<TunnelEvent> ls = new ArrayList<TunnelEvent>();
240 + for (TunnelId id : idSet) {
241 + deletedTunnel = tunnelIdAsKeyStore.get(id);
242 + event = new TunnelEvent(TunnelEvent.Type.TUNNEL_REMOVED,
243 + deletedTunnel);
244 + ls.add(event);
245 + if (producerName.equals(deletedTunnel.providerId())
246 + && type.equals(deletedTunnel.type())) {
247 + tunnelIdAsKeyStore.remove(deletedTunnel.tunnelId());
248 + tunnelNameAsKeyStore.get(deletedTunnel.tunnelName())
249 + .remove(deletedTunnel.tunnelId());
250 + srcAndDstKeyStore.get(key).remove(deletedTunnel.tunnelId());
251 + typeKeyStore.get(deletedTunnel.type())
252 + .remove(deletedTunnel.tunnelId());
253 + }
254 + }
255 + notifyDelegate(ls);
256 + }
257 +
258 + @Override
259 + public Tunnel borrowTunnel(ApplicationId appId, TunnelId tunnelId,
260 + Annotations... annotations) {
261 + Set<TunnelSubscription> orderSet = orderRelationship.get(appId);
262 + if (orderSet == null) {
263 + orderSet = new HashSet<TunnelSubscription>();
264 + }
265 + TunnelSubscription order = new TunnelSubscription(appId, null, null, tunnelId, null, null,
266 + annotations);
267 + Tunnel result = tunnelIdAsKeyStore.get(tunnelId);
268 + if (result != null || Tunnel.State.INACTIVE.equals(result.state())) {
269 + return null;
270 + }
271 + orderSet.add(order);
272 + orderRelationship.put(appId, orderSet);
273 + return result;
274 + }
275 +
276 + @Override
277 + public Collection<Tunnel> borrowTunnel(ApplicationId appId,
278 + TunnelEndPoint src,
279 + TunnelEndPoint dst,
280 + Annotations... annotations) {
281 + Set<TunnelSubscription> orderSet = orderRelationship.get(appId);
282 + if (orderSet == null) {
283 + orderSet = new HashSet<TunnelSubscription>();
284 + }
285 + TunnelSubscription order = new TunnelSubscription(appId, src, dst, null, null, null, annotations);
286 + boolean isExist = orderSet.contains(order);
287 + if (!isExist) {
288 + orderSet.add(order);
289 + }
290 + orderRelationship.put(appId, orderSet);
291 + TunnelKey key = TunnelKey.tunnelKey(src, dst);
292 + Set<TunnelId> idSet = srcAndDstKeyStore.get(key);
293 + if (idSet == null || idSet.size() == 0) {
294 + return Collections.emptySet();
295 + }
296 + Collection<Tunnel> tunnelSet = new HashSet<Tunnel>();
297 + for (TunnelId tunnelId : idSet) {
298 + Tunnel result = tunnelIdAsKeyStore.get(tunnelId);
299 + if (Tunnel.State.ACTIVE.equals(result.state())) {
300 + tunnelSet.add(result);
301 + }
302 + }
303 + return tunnelSet;
304 + }
305 +
306 + @Override
307 + public Collection<Tunnel> borrowTunnel(ApplicationId appId,
308 + TunnelEndPoint src,
309 + TunnelEndPoint dst, Type type,
310 + Annotations... annotations) {
311 + Set<TunnelSubscription> orderSet = orderRelationship.get(appId);
312 + if (orderSet == null) {
313 + orderSet = new HashSet<TunnelSubscription>();
314 + }
315 + TunnelSubscription order = new TunnelSubscription(appId, src, dst, null, type, null, annotations);
316 + boolean isExist = orderSet.contains(order);
317 + if (!isExist) {
318 + orderSet.add(order);
319 + }
320 + orderRelationship.put(appId, orderSet);
321 + TunnelKey key = TunnelKey.tunnelKey(src, dst);
322 + Set<TunnelId> idSet = srcAndDstKeyStore.get(key);
323 + if (idSet == null || idSet.size() == 0) {
324 + return Collections.emptySet();
325 + }
326 + Collection<Tunnel> tunnelSet = new HashSet<Tunnel>();
327 + for (TunnelId tunnelId : idSet) {
328 + Tunnel result = tunnelIdAsKeyStore.get(tunnelId);
329 + if (type.equals(result.type())
330 + && Tunnel.State.ACTIVE.equals(result.state())) {
331 + tunnelSet.add(result);
332 + }
333 + }
334 + return tunnelSet;
335 + }
336 +
337 + @Override
338 + public Collection<Tunnel> borrowTunnel(ApplicationId appId,
339 + TunnelName tunnelName,
340 + Annotations... annotations) {
341 + Set<TunnelSubscription> orderSet = orderRelationship.get(appId);
342 + if (orderSet == null) {
343 + orderSet = new HashSet<TunnelSubscription>();
344 + }
345 + TunnelSubscription order = new TunnelSubscription(appId, null, null, null, null, tunnelName,
346 + annotations);
347 + boolean isExist = orderSet.contains(order);
348 + if (!isExist) {
349 + orderSet.add(order);
350 + }
351 + orderRelationship.put(appId, orderSet);
352 + Set<TunnelId> idSet = tunnelNameAsKeyStore.get(tunnelName);
353 + if (idSet == null || idSet.size() == 0) {
354 + return Collections.emptySet();
355 + }
356 + Collection<Tunnel> tunnelSet = new HashSet<Tunnel>();
357 + for (TunnelId tunnelId : idSet) {
358 + Tunnel result = tunnelIdAsKeyStore.get(tunnelId);
359 + if (Tunnel.State.ACTIVE.equals(result.state())) {
360 + tunnelSet.add(result);
361 + }
362 + }
363 + return tunnelSet;
364 + }
365 +
366 + @Override
367 + public boolean returnTunnel(ApplicationId appId, TunnelName tunnelName,
368 + Annotations... annotations) {
369 + TunnelSubscription order = new TunnelSubscription(appId, null, null, null, null, tunnelName,
370 + annotations);
371 + return deleteOrder(order);
372 + }
373 +
374 + @Override
375 + public boolean returnTunnel(ApplicationId appId, TunnelId tunnelId,
376 + Annotations... annotations) {
377 + TunnelSubscription order = new TunnelSubscription(appId, null, null, tunnelId, null, null,
378 + annotations);
379 + return deleteOrder(order);
380 + }
381 +
382 + @Override
383 + public boolean returnTunnel(ApplicationId appId, TunnelEndPoint src,
384 + TunnelEndPoint dst, Type type,
385 + Annotations... annotations) {
386 + TunnelSubscription order = new TunnelSubscription(appId, src, dst, null, type, null, annotations);
387 + return deleteOrder(order);
388 + }
389 +
390 + @Override
391 + public boolean returnTunnel(ApplicationId appId, TunnelEndPoint src,
392 + TunnelEndPoint dst, Annotations... annotations) {
393 + TunnelSubscription order = new TunnelSubscription(appId, src, dst, null, null, null, annotations);
394 + return deleteOrder(order);
395 + }
396 +
397 + private boolean deleteOrder(TunnelSubscription order) {
398 + Set<TunnelSubscription> orderSet = orderRelationship.get(order.consumerId());
399 + if (orderSet == null) {
400 + return true;
401 + }
402 + if (orderSet.contains(order)) {
403 + orderSet.remove(order);
404 + return true;
405 + }
406 + return false;
407 + }
408 +
409 + @Override
410 + public Tunnel queryTunnel(TunnelId tunnelId) {
411 + return tunnelIdAsKeyStore.get(tunnelId);
412 + }
413 +
414 + @Override
415 + public Collection<TunnelSubscription> queryTunnelSubscription(ApplicationId appId) {
416 + return orderRelationship.get(appId) != null ? ImmutableSet.copyOf(orderRelationship
417 + .get(appId)) : Collections.emptySet();
418 + }
419 +
420 + @Override
421 + public Collection<Tunnel> queryTunnel(Type type) {
422 + Collection<Tunnel> result = new HashSet<Tunnel>();
423 + Set<TunnelId> tunnelIds = typeKeyStore.get(type);
424 + if (tunnelIds == null) {
425 + return Collections.emptySet();
426 + }
427 + for (TunnelId id : tunnelIds) {
428 + result.add(tunnelIdAsKeyStore.get(id));
429 + }
430 + return result.size() == 0 ? Collections.emptySet() : ImmutableSet
431 + .copyOf(result);
432 + }
433 +
434 + @Override
435 + public Collection<Tunnel> queryTunnel(TunnelEndPoint src, TunnelEndPoint dst) {
436 + Collection<Tunnel> result = new HashSet<Tunnel>();
437 + TunnelKey key = TunnelKey.tunnelKey(src, dst);
438 + Set<TunnelId> tunnelIds = srcAndDstKeyStore.get(key);
439 + if (tunnelIds == null) {
440 + return Collections.emptySet();
441 + }
442 + for (TunnelId id : tunnelIds) {
443 + result.add(tunnelIdAsKeyStore.get(id));
444 + }
445 + return result.size() == 0 ? Collections.emptySet() : ImmutableSet
446 + .copyOf(result);
447 + }
448 +
449 + @Override
450 + public int tunnelCount() {
451 + return tunnelIdAsKeyStore.size();
452 + }
453 +
454 + /**
455 + * Uses source TunnelPoint and destination TunnelPoint as map key.
456 + */
457 + private static final class TunnelKey {
458 + private final TunnelEndPoint src;
459 + private final TunnelEndPoint dst;
460 +
461 + private TunnelKey(TunnelEndPoint src, TunnelEndPoint dst) {
462 + this.src = src;
463 + this.dst = dst;
464 +
465 + }
466 +
467 + /**
468 + * create a map key.
469 + *
470 + * @param src
471 + * @param dst
472 + * @return a key using source ip and destination ip
473 + */
474 + static TunnelKey tunnelKey(TunnelEndPoint src, TunnelEndPoint dst) {
475 + return new TunnelKey(src, dst);
476 + }
477 +
478 + @Override
479 + public int hashCode() {
480 + return Objects.hash(src, dst);
481 + }
482 +
483 + @Override
484 + public boolean equals(Object obj) {
485 + if (this == obj) {
486 + return true;
487 + }
488 + if (obj instanceof TunnelKey) {
489 + final TunnelKey other = (TunnelKey) obj;
490 + return Objects.equals(this.src, other.src)
491 + && Objects.equals(this.dst, other.dst);
492 + }
493 + return false;
494 + }
495 +
496 + @Override
497 + public String toString() {
498 + return MoreObjects.toStringHelper(getClass()).add("src", src)
499 + .add("dst", dst).toString();
500 + }
501 + }
502 +
503 +}
1 +/*
2 + * Copyright 2014 Open Networking Laboratory
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 + */
16 +
17 +/**
18 + * Implementation of distributed tunnel store using p2p synchronization protocol.
19 + */
20 +package org.onosproject.store.tunnel.impl;
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
37 <module>host</module> 37 <module>host</module>
38 <module>netconf</module> 38 <module>netconf</module>
39 <module>null</module> 39 <module>null</module>
40 + <module>tunnel</module>
40 </modules> 41 </modules>
41 42
42 <dependencies> 43 <dependencies>
......
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<!--
3 + ~ Copyright 2014 Open Networking Laboratory
4 + ~
5 + ~ Licensed under the Apache License, Version 2.0 (the "License");
6 + ~ you may not use this file except in compliance with the License.
7 + ~ You may obtain a copy of the License at
8 + ~
9 + ~ http://www.apache.org/licenses/LICENSE-2.0
10 + ~
11 + ~ Unless required by applicable law or agreed to in writing, software
12 + ~ distributed under the License is distributed on an "AS IS" BASIS,
13 + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 + ~ See the License for the specific language governing permissions and
15 + ~ limitations under the License.
16 + -->
17 +<project xmlns="http://maven.apache.org/POM/4.0.0"
18 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
20 + <modelVersion>4.0.0</modelVersion>
21 +
22 + <parent>
23 + <groupId>org.onosproject</groupId>
24 + <artifactId>onos-providers</artifactId>
25 + <version>1.2.0-SNAPSHOT</version>
26 + <relativePath>../pom.xml</relativePath>
27 + </parent>
28 +
29 + <artifactId>onos-tunnel-provider</artifactId>
30 + <packaging>bundle</packaging>
31 +
32 + <description>tunnel southbound providers</description>
33 +
34 + <properties>
35 + <onos.app.name>org.onosproject.tunnel</onos.app.name>
36 + </properties>
37 +
38 + <dependencies>
39 + <dependency>
40 + <groupId>org.osgi</groupId>
41 + <artifactId>org.osgi.compendium</artifactId>
42 + </dependency>
43 + <dependency>
44 + <groupId>org.apache.karaf.shell</groupId>
45 + <artifactId>org.apache.karaf.shell.console</artifactId>
46 + </dependency>
47 + <dependency>
48 + <groupId>org.onosproject</groupId>
49 + <artifactId>onos-cli</artifactId>
50 + <version>${project.version}</version>
51 + </dependency>
52 +
53 + <dependency>
54 + <groupId>org.onosproject</groupId>
55 + <artifactId>onos-api</artifactId>
56 + <classifier>tests</classifier>
57 + <scope>test</scope>
58 + </dependency>
59 + </dependencies>
60 +
61 +</project>
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
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 + */
16 +package org.onosproject.provider.tunnel;
17 +
18 +import static org.slf4j.LoggerFactory.getLogger;
19 +
20 +import org.apache.felix.scr.annotations.Activate;
21 +import org.apache.felix.scr.annotations.Component;
22 +import org.apache.felix.scr.annotations.Deactivate;
23 +import org.apache.felix.scr.annotations.Reference;
24 +import org.apache.felix.scr.annotations.ReferenceCardinality;
25 +import org.apache.felix.scr.annotations.Service;
26 +import org.onosproject.cfg.ComponentConfigService;
27 +import org.onosproject.net.ElementId;
28 +import org.onosproject.net.Path;
29 +import org.onosproject.net.provider.AbstractProvider;
30 +import org.onosproject.net.provider.ProviderId;
31 +import org.onosproject.net.tunnel.Tunnel;
32 +import org.onosproject.net.tunnel.TunnelDescription;
33 +import org.onosproject.net.tunnel.TunnelId;
34 +import org.onosproject.net.tunnel.TunnelProvider;
35 +import org.onosproject.net.tunnel.TunnelProviderRegistry;
36 +import org.onosproject.net.tunnel.TunnelProviderService;
37 +import org.osgi.service.component.ComponentContext;
38 +import org.slf4j.Logger;
39 +
40 +/**
41 + * Provider of a fake network environment, i.e. devices, links, hosts, etc. To
42 + * be used for benchmarking only.
43 + */
44 +@Component(immediate = true)
45 +@Service
46 +public class DefaultTunnelProvider extends AbstractProvider
47 + implements TunnelProvider {
48 +
49 + private static final Logger log = getLogger(DefaultTunnelProvider.class);
50 +
51 + static final String PROVIDER_ID = "org.onosproject.provider.tunnel.default";
52 +
53 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
54 + protected ComponentConfigService cfgService;
55 +
56 + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
57 + protected TunnelProviderRegistry tunnelProviderRegistry;
58 +
59 + TunnelProviderService service;
60 +
61 + /**
62 + * Creates a Tunnel provider.
63 + */
64 + public DefaultTunnelProvider() {
65 + super(new ProviderId("default", PROVIDER_ID));
66 + }
67 +
68 + @Activate
69 + public void activate(ComponentContext context) {
70 + cfgService.registerProperties(getClass());
71 + service = tunnelProviderRegistry.register(this);
72 + log.info("Started");
73 + }
74 +
75 + @Deactivate
76 + public void deactivate(ComponentContext context) {
77 + cfgService.unregisterProperties(getClass(), false);
78 + tunnelProviderRegistry.unregister(this);
79 + log.info("Stopped");
80 + }
81 +
82 + @Override
83 + public void setupTunnel(Tunnel tunnel, Path path) {
84 + // TODO Auto-generated method stub
85 +
86 + }
87 +
88 + @Override
89 + public void setupTunnel(ElementId srcElement, Tunnel tunnel, Path path) {
90 + // TODO Auto-generated method stub
91 +
92 + }
93 +
94 + @Override
95 + public void releaseTunnel(Tunnel tunnel) {
96 + // TODO Auto-generated method stub
97 +
98 + }
99 +
100 + @Override
101 + public void releaseTunnel(ElementId srcElement, Tunnel tunnel) {
102 + // TODO Auto-generated method stub
103 +
104 + }
105 +
106 + @Override
107 + public void updateTunnel(Tunnel tunnel, Path path) {
108 + // TODO Auto-generated method stub
109 +
110 + }
111 +
112 + @Override
113 + public void updateTunnel(ElementId srcElement, Tunnel tunnel, Path path) {
114 + // TODO Auto-generated method stub
115 +
116 + }
117 +
118 + @Override
119 + public TunnelId tunnelAdded(TunnelDescription tunnel) {
120 + return service.tunnelAdded(tunnel);
121 + }
122 +
123 + @Override
124 + public void tunnelRemoved(TunnelDescription tunnel) {
125 + service.tunnelRemoved(tunnel);
126 + }
127 +
128 + @Override
129 + public void tunnelUpdated(TunnelDescription tunnel) {
130 + service.tunnelUpdated(tunnel);
131 + }
132 +
133 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
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 + */
16 +package org.onosproject.provider.tunnel.cli;
17 +
18 +import static com.google.common.base.Preconditions.checkArgument;
19 +
20 +import java.util.Optional;
21 +
22 +import org.apache.karaf.shell.commands.Argument;
23 +import org.apache.karaf.shell.commands.Command;
24 +import org.onlab.packet.IpAddress;
25 +import org.onosproject.cli.AbstractShellCommand;
26 +import org.onosproject.core.DefaultGroupId;
27 +import org.onosproject.net.DefaultAnnotations;
28 +import org.onosproject.net.DeviceId;
29 +import org.onosproject.net.PortNumber;
30 +import org.onosproject.net.SparseAnnotations;
31 +import org.onosproject.net.provider.ProviderId;
32 +import org.onosproject.net.tunnel.DefaultOpticalTunnelEndPoint;
33 +import org.onosproject.net.tunnel.DefaultTunnelDescription;
34 +import org.onosproject.net.tunnel.IpTunnelEndPoint;
35 +import org.onosproject.net.tunnel.OpticalLogicId;
36 +import org.onosproject.net.tunnel.OpticalTunnelEndPoint;
37 +import org.onosproject.net.tunnel.Tunnel;
38 +import org.onosproject.net.tunnel.TunnelDescription;
39 +import org.onosproject.net.tunnel.TunnelEndPoint;
40 +import org.onosproject.net.tunnel.TunnelId;
41 +import org.onosproject.net.tunnel.TunnelName;
42 +import org.onosproject.net.tunnel.TunnelProvider;
43 +
44 +/**
45 + * Supports for creating a tunnel by using IP address and optical as tunnel end
46 + * point.
47 + */
48 +@Command(scope = "onos", name = "create-tunnels",
49 +description = "Supports for creating a tunnel by using IP address and optical as tunnel end point now.")
50 +public class CreateTunnelCommand extends AbstractShellCommand {
51 +
52 + @Argument(index = 0, name = "src", description = "Source tunnel point."
53 + + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
54 + + " If creates a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
55 + + " Otherwise src means IP address.", required = true, multiValued = false)
56 + String src = null;
57 +
58 + @Argument(index = 1, name = "dst", description = "Destination tunnel point."
59 + + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
60 + + " If creates a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
61 + + " Otherwise dst means IP address.", required = true, multiValued = false)
62 + String dst = null;
63 + @Argument(index = 2, name = "type", description = "The type of tunnels,"
64 + + " It includes MPLS, VLAN, VXLAN, GRE, ODUK, OCH", required = true, multiValued = false)
65 + String type = null;
66 + @Argument(index = 3, name = "groupId",
67 + description = "Group flow table id which a tunnel match up", required = true, multiValued = false)
68 + String groupId = null;
69 +
70 + @Argument(index = 4, name = "tunnelName",
71 + description = "The name of tunnels", required = false, multiValued = false)
72 + String tunnelName = null;
73 +
74 + @Argument(index = 5, name = "bandWith",
75 + description = "The bandWith attribute of tunnel", required = false, multiValued = false)
76 + String bandWith = null;
77 +
78 + private static final String FMT = "The tunnel identity is %s";
79 +
80 + @Override
81 + protected void execute() {
82 + TunnelProvider service = get(TunnelProvider.class);
83 + ProviderId producerName = new ProviderId("default",
84 + "org.onosproject.provider.tunnel.default");
85 + TunnelEndPoint srcPoint = null;
86 + TunnelEndPoint dstPoint = null;
87 + Tunnel.Type trueType = null;
88 + if ("MPLS".equals(type)) {
89 + trueType = Tunnel.Type.MPLS;
90 + srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
91 + dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
92 + } else if ("VLAN".equals(type)) {
93 + trueType = Tunnel.Type.VLAN;
94 + srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
95 + dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
96 + } else if ("VXLAN".equals(type)) {
97 + trueType = Tunnel.Type.VXLAN;
98 + srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
99 + dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
100 + } else if ("GRE".equals(type)) {
101 + trueType = Tunnel.Type.GRE;
102 + srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
103 + dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
104 + } else if ("ODUK".equals(type)) {
105 + trueType = Tunnel.Type.ODUK;
106 + String[] srcArray = src.split("||");
107 + checkArgument(srcArray.length < 2, "Illegal src formatter.");
108 + String[] dstArray = dst.split("||");
109 + checkArgument(dstArray.length < 2, "Illegal dst formatter.");
110 + srcPoint = new DefaultOpticalTunnelEndPoint(
111 + producerName,
112 + Optional.of(DeviceId
113 + .deviceId(srcArray[0])),
114 + Optional.of(PortNumber
115 + .portNumber(srcArray[1])),
116 + null,
117 + OpticalTunnelEndPoint.Type.LAMBDA,
118 + OpticalLogicId
119 + .logicId(0),
120 + true);
121 + dstPoint = new DefaultOpticalTunnelEndPoint(
122 + producerName,
123 + Optional.of(DeviceId
124 + .deviceId(dstArray[0])),
125 + Optional.of(PortNumber
126 + .portNumber(dstArray[1])),
127 + null,
128 + OpticalTunnelEndPoint.Type.LAMBDA,
129 + OpticalLogicId
130 + .logicId(0),
131 + true);
132 + } else if ("OCH".equals(type)) {
133 + trueType = Tunnel.Type.OCH;
134 + String[] srcArray = src.split("-");
135 + String[] dstArray = dst.split("-");
136 + srcPoint = new DefaultOpticalTunnelEndPoint(
137 + producerName,
138 + Optional.of(DeviceId
139 + .deviceId(srcArray[0])),
140 + Optional.of(PortNumber
141 + .portNumber(srcArray[1])),
142 + null,
143 + OpticalTunnelEndPoint.Type.LAMBDA,
144 + OpticalLogicId
145 + .logicId(0),
146 + true);
147 + dstPoint = new DefaultOpticalTunnelEndPoint(
148 + producerName,
149 + Optional.of(DeviceId
150 + .deviceId(dstArray[0])),
151 + Optional.of(PortNumber
152 + .portNumber(dstArray[1])),
153 + null,
154 + OpticalTunnelEndPoint.Type.LAMBDA,
155 + OpticalLogicId
156 + .logicId(0),
157 + true);
158 + } else {
159 + print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
160 + return;
161 + }
162 +
163 + SparseAnnotations annotations = DefaultAnnotations
164 + .builder()
165 + .set("bandWith", bandWith == null && "".equals(bandWith) ? "0" : bandWith)
166 + .build();
167 + TunnelDescription tunnel = new DefaultTunnelDescription(
168 + null,
169 + srcPoint,
170 + dstPoint,
171 + trueType,
172 + new DefaultGroupId(
173 + Integer.valueOf(groupId)
174 + .intValue()),
175 + producerName,
176 + TunnelName
177 + .tunnelName(tunnelName),
178 + annotations);
179 + TunnelId tunnelId = service.tunnelAdded(tunnel);
180 + print(FMT, tunnelId.id());
181 + }
182 +
183 +}
1 +/*
2 + * Copyright 2014-2015 Open Networking Laboratory
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 + */
16 +package org.onosproject.provider.tunnel.cli;
17 +
18 +import java.util.Optional;
19 +
20 +import org.apache.karaf.shell.commands.Argument;
21 +import org.apache.karaf.shell.commands.Command;
22 +import org.onlab.packet.IpAddress;
23 +import org.onosproject.cli.AbstractShellCommand;
24 +import org.onosproject.net.DeviceId;
25 +import org.onosproject.net.PortNumber;
26 +import org.onosproject.net.provider.ProviderId;
27 +import org.onosproject.net.tunnel.DefaultOpticalTunnelEndPoint;
28 +import org.onosproject.net.tunnel.DefaultTunnelDescription;
29 +import org.onosproject.net.tunnel.IpTunnelEndPoint;
30 +import org.onosproject.net.tunnel.OpticalLogicId;
31 +import org.onosproject.net.tunnel.OpticalTunnelEndPoint;
32 +import org.onosproject.net.tunnel.Tunnel;
33 +import org.onosproject.net.tunnel.TunnelDescription;
34 +import org.onosproject.net.tunnel.TunnelEndPoint;
35 +import org.onosproject.net.tunnel.TunnelProvider;
36 +
37 +/**
38 + * Supports for removing all tunnels by using IP address and optical as tunnel
39 + * end point now. It's used by producers.
40 + */
41 +@Command(scope = "onos", name = "remove-tunnels", description = "Supports for removing all tunnels by using IP address"
42 + + " and optical as tunnel end point now. It's used by producers.")
43 +public class RemoveTunnelCommand extends AbstractShellCommand {
44 + @Argument(index = 0, name = "src", description = "Source tunnel point."
45 + + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
46 + + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
47 + + " Otherwise src means IP address.", required = true, multiValued = false)
48 + String src = null;
49 + @Argument(index = 1, name = "dst", description = "Destination tunnel point."
50 + + " Only supports for IpTunnelEndPoint and OpticalTunnelEndPoint as end point now."
51 + + " If deletess a ODUK or OCH type tunnel, the formatter of this argument is DeviceId-PortNumber."
52 + + " Otherwise dst means IP address.", required = true, multiValued = false)
53 + String dst = null;
54 +
55 + @Argument(index = 2, name = "type", description = "The type of tunnels,"
56 + + " It includes MPLS, VLAN, VXLAN, GRE, ODUK, OCH", required = true, multiValued = false)
57 + String type = null;
58 +
59 + @Override
60 + protected void execute() {
61 + TunnelProvider service = get(TunnelProvider.class);
62 + ProviderId producerName = new ProviderId("default",
63 + "org.onosproject.provider.tunnel.default");
64 + TunnelEndPoint srcPoint = null;
65 + TunnelEndPoint dstPoint = null;
66 + Tunnel.Type trueType = null;
67 + if ("MPLS".equals(type)) {
68 + trueType = Tunnel.Type.MPLS;
69 + srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
70 + dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
71 + } else if ("VLAN".equals(type)) {
72 + trueType = Tunnel.Type.VLAN;
73 + srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
74 + dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
75 + } else if ("VXLAN".equals(type)) {
76 + trueType = Tunnel.Type.VXLAN;
77 + srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
78 + dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
79 + } else if ("GRE".equals(type)) {
80 + trueType = Tunnel.Type.GRE;
81 + srcPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(src));
82 + dstPoint = IpTunnelEndPoint.ipTunnelPoint(IpAddress.valueOf(dst));
83 + } else if ("ODUK".equals(type)) {
84 + trueType = Tunnel.Type.ODUK;
85 + String[] srcArray = src.split("-");
86 + String[] dstArray = dst.split("-");
87 + srcPoint = new DefaultOpticalTunnelEndPoint(
88 + producerName,
89 + Optional.of(DeviceId
90 + .deviceId(srcArray[0])),
91 + Optional.of(PortNumber
92 + .portNumber(srcArray[1])),
93 + null,
94 + OpticalTunnelEndPoint.Type.LAMBDA,
95 + OpticalLogicId
96 + .logicId(0),
97 + true);
98 + dstPoint = new DefaultOpticalTunnelEndPoint(
99 + producerName,
100 + Optional.of(DeviceId
101 + .deviceId(dstArray[0])),
102 + Optional.of(PortNumber
103 + .portNumber(dstArray[1])),
104 + null,
105 + OpticalTunnelEndPoint.Type.LAMBDA,
106 + OpticalLogicId
107 + .logicId(0),
108 + true);
109 + } else if ("OCH".equals(type)) {
110 + trueType = Tunnel.Type.OCH;
111 + String[] srcArray = src.split("-");
112 + String[] dstArray = dst.split("-");
113 + srcPoint = new DefaultOpticalTunnelEndPoint(
114 + producerName,
115 + Optional.of(DeviceId
116 + .deviceId(srcArray[0])),
117 + Optional.of(PortNumber
118 + .portNumber(srcArray[1])),
119 + null,
120 + OpticalTunnelEndPoint.Type.LAMBDA,
121 + OpticalLogicId
122 + .logicId(0),
123 + true);
124 + dstPoint = new DefaultOpticalTunnelEndPoint(
125 + producerName,
126 + Optional.of(DeviceId
127 + .deviceId(dstArray[0])),
128 + Optional.of(PortNumber
129 + .portNumber(dstArray[1])),
130 + null,
131 + OpticalTunnelEndPoint.Type.LAMBDA,
132 + OpticalLogicId
133 + .logicId(0),
134 + true);
135 + } else {
136 + print("Illegal tunnel type. Please input MPLS, VLAN, VXLAN, GRE, ODUK or OCH.");
137 + return;
138 + }
139 + TunnelDescription tunnel = new DefaultTunnelDescription(null, srcPoint,
140 + dstPoint,
141 + trueType, null,
142 + producerName,
143 + null);
144 + service.tunnelRemoved(tunnel);
145 + }
146 +
147 +}
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
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 + */
16 +
17 +/**
18 + * Null provider CLI commands and completers.
19 + */
20 +package org.onosproject.provider.tunnel.cli;
1 +/*
2 + * Copyright 2015 Open Networking Laboratory
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 + */
16 +
17 +/**
18 + * Set of null south-bound providers which permit simulating a network
19 + * topology using fake devices, links, hosts, etc.
20 + */
21 +package org.onosproject.provider.tunnel;
1 +<!--
2 + ~ Copyright 2015 Open Networking Laboratory
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 + -->
16 +<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
17 +
18 + <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
19 + <command>
20 + <action class="org.onosproject.provider.tunnel.cli.CreateTunnelCommand"/>
21 + </command>
22 + <command>
23 + <action class="org.onosproject.provider.tunnel.cli.RemoveTunnelCommand"/>
24 + </command>
25 + </command-bundle>
26 +</blueprint>