Committed by
Gerrit Code Review
[ONOS-1925]
1.fix javadocs bugs. 2.add pcep tunnel provider; 3.change pcep to pcep app; 4.fix some bugs according to review suggestions. Change-Id: I4b90d9bf871dee3be70615d66db3d74f2fd85389
Showing
27 changed files
with
1963 additions
and
0 deletions
apps/pcep-api/pom.xml
0 → 100644
1 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
2 | + <modelVersion>4.0.0</modelVersion> | ||
3 | + <parent> | ||
4 | + <groupId>org.onosproject</groupId> | ||
5 | + <artifactId>onos-apps</artifactId> | ||
6 | + <version>1.2.0-SNAPSHOT</version> | ||
7 | + </parent> | ||
8 | + <artifactId>onos-app-pcep-api</artifactId> | ||
9 | + <packaging>bundle</packaging> | ||
10 | +</project> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
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.pcep.api; | ||
17 | + | ||
18 | +import org.onosproject.net.DeviceId; | ||
19 | + | ||
20 | +/** | ||
21 | + * Abstraction of an PCEP controller. Serves as a one stop shop for obtaining | ||
22 | + * PCEP devices and (un)register listeners on PCEP events | ||
23 | + */ | ||
24 | +public interface PcepController { | ||
25 | + | ||
26 | + /** | ||
27 | + * Returns all switches known to this PCEP controller. | ||
28 | + * | ||
29 | + * @return Iterable of did elements | ||
30 | + */ | ||
31 | + public Iterable<PcepSwitch> getSwitches(); | ||
32 | + | ||
33 | + /** | ||
34 | + * Return a switch with a specified did. | ||
35 | + * | ||
36 | + * @param did of a device | ||
37 | + * @return a pcep device | ||
38 | + */ | ||
39 | + public PcepSwitch getSwitch(PcepDpid did); | ||
40 | + | ||
41 | + /** | ||
42 | + * Register a listener for meta events that occur to PCEP devices. | ||
43 | + * | ||
44 | + * @param listener the listener to notify | ||
45 | + */ | ||
46 | + public void addListener(PcepSwitchListener listener); | ||
47 | + | ||
48 | + /** | ||
49 | + * Unregister a listener. | ||
50 | + * | ||
51 | + * @param listener the listener to unregister | ||
52 | + */ | ||
53 | + public void removeListener(PcepSwitchListener listener); | ||
54 | + | ||
55 | + /** | ||
56 | + * Register a listener for meta events that occur to PCEP links. | ||
57 | + * | ||
58 | + * @param listener the listener to notify | ||
59 | + */ | ||
60 | + public void addLinkListener(PcepLinkListener listener); | ||
61 | + | ||
62 | + /** | ||
63 | + * Unregister a link listener. | ||
64 | + * | ||
65 | + * @param listener the listener to unregister | ||
66 | + */ | ||
67 | + public void removeLinkListener(PcepLinkListener listener); | ||
68 | + | ||
69 | + /** | ||
70 | + * Register a listener for meta events that occur to PCEP tunnel. | ||
71 | + * | ||
72 | + * @param listener the listener to notify | ||
73 | + */ | ||
74 | + public void addTunnelListener(PcepTunnelListener listener); | ||
75 | + | ||
76 | + /** | ||
77 | + * Unregister a tunnel listener. | ||
78 | + * | ||
79 | + * @param listener the listener to unregister | ||
80 | + */ | ||
81 | + public void removeTunnelListener(PcepTunnelListener listener); | ||
82 | + | ||
83 | + /** | ||
84 | + * Setup a tunnel through pcep controller. | ||
85 | + * | ||
86 | + * @param srcDid src deviceId of tunnel | ||
87 | + * @param dstDid dst deviceId of tunnel | ||
88 | + * @param srcPort src port | ||
89 | + * @param dstPort dst port | ||
90 | + * @param bandwidth andwidth of tunnel | ||
91 | + * @param name tunnel name | ||
92 | + * @return pcep tunnel | ||
93 | + */ | ||
94 | + public PcepTunnel applyTunnel(DeviceId srcDid, DeviceId dstDid, | ||
95 | + long srcPort, long dstPort, long bandwidth, | ||
96 | + String name); | ||
97 | + | ||
98 | + /** | ||
99 | + * Delete tunnel by id. | ||
100 | + * | ||
101 | + * @param id pcep tunnel id. | ||
102 | + * @return true or false | ||
103 | + */ | ||
104 | + public Boolean deleteTunnel(String id); | ||
105 | + | ||
106 | + /** | ||
107 | + * Update tunnel bandwidth by tunnel id. | ||
108 | + * | ||
109 | + * @param id tunnel id | ||
110 | + * @param bandwidth bandwidth of a tunnel | ||
111 | + * @return true or false | ||
112 | + */ | ||
113 | + public Boolean updateTunnelBandwidth(String id, long bandwidth); | ||
114 | + | ||
115 | +} |
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 | +package org.onosproject.pcep.api; | ||
17 | + | ||
18 | +import java.net.URI; | ||
19 | +import java.net.URISyntaxException; | ||
20 | + | ||
21 | +import org.onosproject.pcep.tools.PcepTools; | ||
22 | + | ||
23 | +/** | ||
24 | + * The class representing a network switch PCEPDid. This class is immutable. | ||
25 | + */ | ||
26 | +public final class PcepDpid { | ||
27 | + | ||
28 | + private static final String SCHEME = "pcep"; | ||
29 | + private static final long UNKNOWN = 0; | ||
30 | + private long nodeId; | ||
31 | + | ||
32 | + /** | ||
33 | + * Default constructor. | ||
34 | + */ | ||
35 | + public PcepDpid() { | ||
36 | + this.nodeId = PcepDpid.UNKNOWN; | ||
37 | + } | ||
38 | + | ||
39 | + /** | ||
40 | + * Constructor from a long value. | ||
41 | + * | ||
42 | + * @param value long value for construct | ||
43 | + */ | ||
44 | + public PcepDpid(long value) { | ||
45 | + this.nodeId = value; | ||
46 | + } | ||
47 | + | ||
48 | + /** | ||
49 | + * Constructor from a String. | ||
50 | + * | ||
51 | + * @param value string value for construct | ||
52 | + */ | ||
53 | + public PcepDpid(String value) { | ||
54 | + this.nodeId = Long.parseLong(value, 16); | ||
55 | + } | ||
56 | + | ||
57 | + /** | ||
58 | + * Produces device URI from the given DPID. | ||
59 | + * | ||
60 | + * @param dpid device dpid | ||
61 | + * @return device URI | ||
62 | + */ | ||
63 | + public static URI uri(PcepDpid dpid) { | ||
64 | + return uri(dpid.nodeId); | ||
65 | + } | ||
66 | + | ||
67 | + /** | ||
68 | + * Produces device long from the given string which comes from the uri | ||
69 | + * method. | ||
70 | + * | ||
71 | + * @param value string value which produced by uri method. | ||
72 | + * @return a long value. | ||
73 | + */ | ||
74 | + public static long toLong(String value) { | ||
75 | + return PcepTools.ipToLong(value.replace(SCHEME, "")); | ||
76 | + } | ||
77 | + | ||
78 | + /** | ||
79 | + * Produces device URI from the given DPID long. | ||
80 | + * | ||
81 | + * @param value device dpid as long | ||
82 | + * @return device URI | ||
83 | + */ | ||
84 | + public static URI uri(long value) { | ||
85 | + try { | ||
86 | + return new URI(SCHEME, PcepTools.longToIp(value), null); | ||
87 | + } catch (URISyntaxException e) { | ||
88 | + return null; | ||
89 | + } | ||
90 | + } | ||
91 | + | ||
92 | + /** | ||
93 | + * Return a device id with the form of long. | ||
94 | + * | ||
95 | + * @return long value | ||
96 | + */ | ||
97 | + public long value() { | ||
98 | + return this.nodeId; | ||
99 | + } | ||
100 | + | ||
101 | +} |
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.pcep.api; | ||
17 | + | ||
18 | +/** | ||
19 | + * Description of a pcep tunnel hop node.a hop list consists of a number of hop | ||
20 | + * node. | ||
21 | + */ | ||
22 | +public class PcepHopNodeDescription { | ||
23 | + private PcepDpid deviceId; | ||
24 | + private long portNum; | ||
25 | + | ||
26 | + /** | ||
27 | + * Get the pcepdpid of a node. | ||
28 | + * | ||
29 | + * @return device pcepdpid. | ||
30 | + */ | ||
31 | + public PcepDpid getDeviceId() { | ||
32 | + return deviceId; | ||
33 | + } | ||
34 | + | ||
35 | + /** | ||
36 | + * Set the pcepdpid of a node. | ||
37 | + * | ||
38 | + * @param deviceId pcep dpid of a node. | ||
39 | + */ | ||
40 | + public void setDeviceId(PcepDpid deviceId) { | ||
41 | + this.deviceId = deviceId; | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * Get the port number of a node. | ||
46 | + * | ||
47 | + * @return port number. | ||
48 | + */ | ||
49 | + public long getPortNum() { | ||
50 | + return portNum; | ||
51 | + } | ||
52 | + | ||
53 | + /** | ||
54 | + * Set the port number of a node. | ||
55 | + * | ||
56 | + * @param portNum port number of a node. | ||
57 | + */ | ||
58 | + public void setPortNum(long portNum) { | ||
59 | + this.portNum = portNum; | ||
60 | + } | ||
61 | + | ||
62 | +} |
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.pcep.api; | ||
17 | + | ||
18 | +/** | ||
19 | + * Abstraction of a huawei network infrastructure link. | ||
20 | + */ | ||
21 | +public interface PcepLink extends PcepOperator { | ||
22 | + | ||
23 | + public enum SubType { | ||
24 | + /** | ||
25 | + * Optical Transmission Section Link. | ||
26 | + */ | ||
27 | + OTS, | ||
28 | + | ||
29 | + /** | ||
30 | + * Optical Physical Section Link. | ||
31 | + */ | ||
32 | + OPS, | ||
33 | + | ||
34 | + /** | ||
35 | + * User-to-Network Interface Link. | ||
36 | + */ | ||
37 | + UNI, | ||
38 | + | ||
39 | + /** | ||
40 | + * Optical channel Data Unit-k link. | ||
41 | + */ | ||
42 | + ODUk, | ||
43 | + | ||
44 | + /** | ||
45 | + * Optical Transport Network link. | ||
46 | + */ | ||
47 | + OTU, | ||
48 | + } | ||
49 | + | ||
50 | + | ||
51 | + | ||
52 | + /** | ||
53 | + * Get the link endpoint port type. | ||
54 | + * | ||
55 | + * @return endpoint port type | ||
56 | + */ | ||
57 | + public String portType(); | ||
58 | + | ||
59 | + /** | ||
60 | + * Get the link sub type,OTS,OPS,PKT_OPTICAL or ODUK. | ||
61 | + * | ||
62 | + * @return link subType | ||
63 | + */ | ||
64 | + | ||
65 | + public SubType linkSubType(); | ||
66 | + | ||
67 | + /** | ||
68 | + * Get the link state, up or down. | ||
69 | + * | ||
70 | + * @return link state | ||
71 | + */ | ||
72 | + public String linkState(); | ||
73 | + | ||
74 | + /** | ||
75 | + * Get the distance of a link. | ||
76 | + * | ||
77 | + * @return distance | ||
78 | + */ | ||
79 | + public int linkDistance(); | ||
80 | + | ||
81 | + /** | ||
82 | + * Get the capacity type of a link,1: WAVELENGTHNUM, 2:SLOTNUM, 3, | ||
83 | + * BANDWIDTH. | ||
84 | + * | ||
85 | + * @return capacity type | ||
86 | + */ | ||
87 | + public String linkCapacityType(); | ||
88 | + | ||
89 | + /** | ||
90 | + * Get the available capacity value ,such as available bandwidth. | ||
91 | + * | ||
92 | + * @return availValue | ||
93 | + */ | ||
94 | + public int linkAvailValue(); | ||
95 | + | ||
96 | + /** | ||
97 | + * Get the max capacity value ,such as max bandwidth. | ||
98 | + * | ||
99 | + * @return maxValue | ||
100 | + */ | ||
101 | + public int linkMaxValue(); | ||
102 | + | ||
103 | + /** | ||
104 | + * Get the source device did of a link. | ||
105 | + * | ||
106 | + * @return source did | ||
107 | + */ | ||
108 | + public PcepDpid linkSrcDeviceID(); | ||
109 | + | ||
110 | + /** | ||
111 | + * Get the destination device did of a link. | ||
112 | + * | ||
113 | + * @return destination did | ||
114 | + */ | ||
115 | + public PcepDpid linkDstDeviceId(); | ||
116 | + | ||
117 | + /** | ||
118 | + * Get the source port number of a link,the port consists of shelf id, sub | ||
119 | + * card id, board id, and port id of a Huawei Device. | ||
120 | + * | ||
121 | + * @return port number | ||
122 | + */ | ||
123 | + public long linkSrcPort(); | ||
124 | + | ||
125 | + /** | ||
126 | + * Get the destination port number of a link,the port consists of shelf id, | ||
127 | + * sub card id, board id, and port id of a Huawei Device. | ||
128 | + * | ||
129 | + * @return port number | ||
130 | + */ | ||
131 | + public long linkDstPort(); | ||
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.pcep.api; | ||
17 | + | ||
18 | +/** | ||
19 | + * Allows for providers interested in Link events to be notified. | ||
20 | + */ | ||
21 | +public interface PcepLinkListener { | ||
22 | + | ||
23 | + /** | ||
24 | + * Notify that get a packet of link from network and need do some | ||
25 | + * processing. | ||
26 | + * | ||
27 | + * @param link pcep link | ||
28 | + */ | ||
29 | + public void handlePCEPlink(PcepLink link); | ||
30 | +} |
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.pcep.api; | ||
17 | + | ||
18 | +/** | ||
19 | + * A interface defined operator type, and provide a method to get the operator | ||
20 | + * type. | ||
21 | + * | ||
22 | + */ | ||
23 | +public interface PcepOperator { | ||
24 | + | ||
25 | + public enum OperationType { | ||
26 | + | ||
27 | + ADD, UPDATE, DELETE, | ||
28 | + } | ||
29 | + | ||
30 | + /** | ||
31 | + * Get operate type of a event,such as device add ,device update. | ||
32 | + * | ||
33 | + * @return operation type. | ||
34 | + */ | ||
35 | + public OperationType getOperationType(); | ||
36 | +} |
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.pcep.api; | ||
17 | + | ||
18 | +/* | ||
19 | + * Represent to provider facing side of a switch | ||
20 | + */ | ||
21 | +public interface PcepSwitch extends PcepOperator { | ||
22 | + | ||
23 | + public static enum SubDeviceType { | ||
24 | + /* optical device */ | ||
25 | + ROADM, | ||
26 | + | ||
27 | + /* electronic device */ | ||
28 | + OTN, | ||
29 | + | ||
30 | + /* router */ | ||
31 | + ROUTER, | ||
32 | + | ||
33 | + /* unkown type */ | ||
34 | + UNKNOW, | ||
35 | + } | ||
36 | + | ||
37 | + /** | ||
38 | + * Gets a string version of the ID for this switch. | ||
39 | + * @return string version of the ID | ||
40 | + */ | ||
41 | + public String getStringId(); | ||
42 | + | ||
43 | + /** | ||
44 | + * Gets the datapathId of the switch. | ||
45 | + * @return the switch dpid in long format | ||
46 | + */ | ||
47 | + public long getId(); | ||
48 | + | ||
49 | + public long getNeId(); | ||
50 | + | ||
51 | + /** | ||
52 | + * Gets the sub type of the device. | ||
53 | + * @return the sub type | ||
54 | + */ | ||
55 | + public SubDeviceType getDeviceSubType(); | ||
56 | + | ||
57 | + /** | ||
58 | + * fetch the manufacturer description. | ||
59 | + * @return the description | ||
60 | + */ | ||
61 | + public String manufacturerDescription(); | ||
62 | + | ||
63 | + /** | ||
64 | + * fetch the datapath description. | ||
65 | + * @return the description | ||
66 | + */ | ||
67 | + public String datapathDescription(); | ||
68 | + | ||
69 | + /** | ||
70 | + * fetch the hardware description. | ||
71 | + * @return the description | ||
72 | + */ | ||
73 | + public String hardwareDescription(); | ||
74 | + | ||
75 | + /** | ||
76 | + * fetch the software description. | ||
77 | + * @return the description | ||
78 | + */ | ||
79 | + public String softwareDescription(); | ||
80 | + | ||
81 | + /** | ||
82 | + * fetch the serial number. | ||
83 | + * @return the serial | ||
84 | + */ | ||
85 | + public String serialNumber(); | ||
86 | + | ||
87 | + /** | ||
88 | + * Indicates if this switch is optical. | ||
89 | + * @return true if optical | ||
90 | + */ | ||
91 | + public boolean isOptical(); | ||
92 | +} |
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.pcep.api; | ||
17 | + | ||
18 | +/** | ||
19 | + * Notifies providers about switch in events. | ||
20 | + */ | ||
21 | +public interface PcepSwitchListener { | ||
22 | + | ||
23 | + /** | ||
24 | + * Notify that the switch was added. | ||
25 | + * | ||
26 | + * @param dpid the switch where the event occurred | ||
27 | + */ | ||
28 | + public void switchAdded(PcepDpid dpid); | ||
29 | + | ||
30 | + /** | ||
31 | + * Notify that the switch was removed. | ||
32 | + * | ||
33 | + * @param dpid the switch where the event occurred. | ||
34 | + */ | ||
35 | + public void switchRemoved(PcepDpid dpid); | ||
36 | + | ||
37 | + /** | ||
38 | + * Notify that the switch has changed in some way. | ||
39 | + * | ||
40 | + * @param dpid the switch that changed | ||
41 | + */ | ||
42 | + public void switchChanged(PcepDpid dpid); | ||
43 | + | ||
44 | +} |
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 | +package org.onosproject.pcep.api; | ||
18 | + | ||
19 | +import java.util.List; | ||
20 | + | ||
21 | +/** | ||
22 | + * Abstraction of a generalized PCEP Tunnel entity (bandwidth pipe) for | ||
23 | + * L2 networks or L1/L0 networks, representation of e.g., VLAN, L1 ODUk | ||
24 | + * connection, WDM OCH, etc.. | ||
25 | + */ | ||
26 | +public interface PcepTunnel extends PcepOperator { | ||
27 | + | ||
28 | + /** | ||
29 | + * Describe the type of a tunnel. | ||
30 | + */ | ||
31 | + public static enum Type { | ||
32 | + | ||
33 | + /** | ||
34 | + * Signifies that this is a L0 OCH tunnel. | ||
35 | + */ | ||
36 | + OCH, | ||
37 | + | ||
38 | + /** | ||
39 | + * Signifies that this is a L1 OTN tunnel. | ||
40 | + */ | ||
41 | + OTN, | ||
42 | + | ||
43 | + /** | ||
44 | + * Signifies that this is a L2 tunnel. | ||
45 | + */ | ||
46 | + UNI, | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * The ability of a tunnel. | ||
51 | + */ | ||
52 | + public static enum Ability { | ||
53 | + /** | ||
54 | + * no protected tunnel,if the tunnel is broken ,then the user is out of | ||
55 | + * service. | ||
56 | + */ | ||
57 | + NOPROTECTED, | ||
58 | + | ||
59 | + /** | ||
60 | + * tunnel with rerouter ability.if a tunnel is broken, the tunnel will | ||
61 | + * try to find another path to provider service. | ||
62 | + */ | ||
63 | + SILVER, | ||
64 | + | ||
65 | + /** | ||
66 | + * tunnel with 1 + 1 rerouter ability.if a tunnel is broken, there'll be | ||
67 | + * another tunnel providing service at once. | ||
68 | + */ | ||
69 | + DIAMOND | ||
70 | + } | ||
71 | + | ||
72 | + public static enum PATHTYPE { | ||
73 | + | ||
74 | + /** | ||
75 | + * the preferred path. | ||
76 | + */ | ||
77 | + FIRST, | ||
78 | + | ||
79 | + /** | ||
80 | + * the alternate path. | ||
81 | + */ | ||
82 | + SECOND | ||
83 | + } | ||
84 | + | ||
85 | + /** | ||
86 | + * Get the type of a tunnel. | ||
87 | + * | ||
88 | + * @return tunnel type | ||
89 | + */ | ||
90 | + public Type type(); | ||
91 | + | ||
92 | + /** | ||
93 | + * Get the name of a tunnel. | ||
94 | + * | ||
95 | + * @return tunnel name | ||
96 | + */ | ||
97 | + public String name(); | ||
98 | + | ||
99 | + /** | ||
100 | + * Get the device id of destination endpoint of a tunnel. | ||
101 | + * | ||
102 | + * @return device id | ||
103 | + */ | ||
104 | + public PcepDpid srcDeviceID(); | ||
105 | + | ||
106 | + /** | ||
107 | + * Get the device id of source endpoint of a tunnel. | ||
108 | + * | ||
109 | + * @return device id | ||
110 | + */ | ||
111 | + public PcepDpid dstDeviceId(); | ||
112 | + | ||
113 | + /** | ||
114 | + * Get source port of a tunnel. | ||
115 | + * | ||
116 | + * @return port number | ||
117 | + */ | ||
118 | + public long srcPort(); | ||
119 | + | ||
120 | + /** | ||
121 | + * Get destination port of a tunnel. | ||
122 | + * | ||
123 | + * @return port number | ||
124 | + */ | ||
125 | + public long dstPort(); | ||
126 | + | ||
127 | + /** | ||
128 | + * Get the bandwidth of a tunnel. | ||
129 | + * | ||
130 | + * @return bandwidth | ||
131 | + */ | ||
132 | + public long bandWidth(); | ||
133 | + | ||
134 | + /** | ||
135 | + * Get the tunnel id. | ||
136 | + * | ||
137 | + * @return id of the PCEP tunnel | ||
138 | + */ | ||
139 | + public long id(); | ||
140 | + | ||
141 | + /** | ||
142 | + * Get the detail hop list of a tunnel. | ||
143 | + * | ||
144 | + * @return hop list | ||
145 | + */ | ||
146 | + public List<PcepHopNodeDescription> getHopList(); | ||
147 | + | ||
148 | + /** | ||
149 | + * Get the instance of a pcep tunnel,a instance is used to mark the times of a tunnel created. | ||
150 | + * instance and id identify a tunnel together. | ||
151 | + * | ||
152 | + * @return the instance of a tunnel. | ||
153 | + */ | ||
154 | + public int getInstance(); | ||
155 | + | ||
156 | + /** | ||
157 | + * Get the ability of a tunnel.NOPROTECTED,SILVER,or DIAMOND. | ||
158 | + * | ||
159 | + * @return ability of the tunenl | ||
160 | + */ | ||
161 | + public Ability getSla(); | ||
162 | + | ||
163 | + /** | ||
164 | + * Get the path type of a path if the tunnel's ability is diamond . | ||
165 | + * | ||
166 | + * @return the type of a path, the preferred or alternate. | ||
167 | + */ | ||
168 | + public PATHTYPE getPathType(); | ||
169 | + | ||
170 | + /** | ||
171 | + * Get the under lay tunnel id of VLAN tunnel. | ||
172 | + * | ||
173 | + * @return the tunnel id of a OCH tunnel under lay of a VLAN tunnel. | ||
174 | + */ | ||
175 | + public long underLayTunnelId(); | ||
176 | + | ||
177 | +} |
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.pcep.api; | ||
17 | + | ||
18 | +/** | ||
19 | + * Allows for providers interested in tunnel events to be notified. | ||
20 | + */ | ||
21 | +public interface PcepTunnelListener { | ||
22 | + | ||
23 | + /** | ||
24 | + * Notify that get a packet of tunnel from network and need do some | ||
25 | + * processing. | ||
26 | + * | ||
27 | + * @param tunnel a pceptunnel. | ||
28 | + */ | ||
29 | + public void handlePCEPTunnel(PcepTunnel tunnel); | ||
30 | + | ||
31 | +} |
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 | + * PCEP controller API. | ||
19 | + */ | ||
20 | +package org.onosproject.pcep.api; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
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.pcep.tools; | ||
17 | + | ||
18 | +import javax.xml.bind.DatatypeConverter; | ||
19 | + | ||
20 | +/** | ||
21 | + * tools fo pcep app. | ||
22 | + */ | ||
23 | +public abstract class PcepTools { | ||
24 | + | ||
25 | + private PcepTools() { | ||
26 | + | ||
27 | + } | ||
28 | + | ||
29 | + /** | ||
30 | + * Converts decimal byte array to a hex string. | ||
31 | + * | ||
32 | + * @param byteArray byte array | ||
33 | + * @return a hex string | ||
34 | + */ | ||
35 | + public static String toHexString(byte[] byteArray) { | ||
36 | + return DatatypeConverter.printHexBinary(byteArray); | ||
37 | + } | ||
38 | + | ||
39 | + /** | ||
40 | + * Converts a hex string to a decimal byte array. | ||
41 | + * | ||
42 | + * @param hexString a hex string | ||
43 | + * @return byte array | ||
44 | + */ | ||
45 | + public static byte[] toByteArray(String hexString) { | ||
46 | + return DatatypeConverter.parseHexBinary(hexString); | ||
47 | + } | ||
48 | + | ||
49 | + /** | ||
50 | + * Converts a byte array to a decimal string. | ||
51 | + * | ||
52 | + * @param bytes a byte array | ||
53 | + * @return a decimal string | ||
54 | + */ | ||
55 | + public static String toDecimalString(byte[] bytes) { | ||
56 | + String str = ""; | ||
57 | + for (int i = 0; i < bytes.length; i++) { | ||
58 | + str += String.valueOf(bytes[i]); | ||
59 | + } | ||
60 | + return str; | ||
61 | + } | ||
62 | + | ||
63 | + /** | ||
64 | + * convert a string to the form of ip address. | ||
65 | + * | ||
66 | + * @param str a string | ||
67 | + * @return a string with ip format | ||
68 | + */ | ||
69 | + public static String stringToIp(String str) { | ||
70 | + long ipInt = Long.parseLong(str, 16); | ||
71 | + return longToIp(ipInt); | ||
72 | + } | ||
73 | + | ||
74 | + /** | ||
75 | + * convert a long to ip format. | ||
76 | + * | ||
77 | + * @param ipLong a decimal number. | ||
78 | + * @return a ip format string | ||
79 | + */ | ||
80 | + public static String longToIp(long ipLong) { | ||
81 | + StringBuilder sb = new StringBuilder(); | ||
82 | + sb.append((ipLong >> 24) & 0xFF).append("."); | ||
83 | + sb.append((ipLong >> 16) & 0xFF).append("."); | ||
84 | + sb.append((ipLong >> 8) & 0xFF).append("."); | ||
85 | + sb.append(ipLong & 0xFF); | ||
86 | + return sb.toString(); | ||
87 | + } | ||
88 | + | ||
89 | + /** | ||
90 | + * convert a string with ip format to a long. | ||
91 | + * | ||
92 | + * @param strIp a string with ip format | ||
93 | + * @return a long number | ||
94 | + */ | ||
95 | + public static long ipToLong(String strIp) { | ||
96 | + long[] ip = new long[4]; | ||
97 | + int position1 = strIp.indexOf("."); | ||
98 | + int position2 = strIp.indexOf(".", position1 + 1); | ||
99 | + int position3 = strIp.indexOf(".", position2 + 1); | ||
100 | + ip[0] = Long.parseLong(strIp.substring(0, position1)); | ||
101 | + ip[1] = Long.parseLong(strIp.substring(position1 + 1, position2)); | ||
102 | + ip[2] = Long.parseLong(strIp.substring(position2 + 1, position3)); | ||
103 | + ip[3] = Long.parseLong(strIp.substring(position3 + 1)); | ||
104 | + return (ip[0] << 24) + (ip[1] << 16) + (ip[2] << 8) + ip[3]; | ||
105 | + } | ||
106 | + | ||
107 | + /** | ||
108 | + * get a integer value from a cut string. | ||
109 | + * | ||
110 | + * @param str a whole string | ||
111 | + * @param base cut the string from this index | ||
112 | + * @param offset the offset when execute the cut | ||
113 | + * @return a integer value | ||
114 | + */ | ||
115 | + public static int tranferHexStringToInt(String str, int base, int offset) { | ||
116 | + return Integer.parseInt(str.substring(base, offset), 16); | ||
117 | + | ||
118 | + } | ||
119 | +} |
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 | + * tools for pcep app. | ||
18 | + */ | ||
19 | +package org.onosproject.pcep.tools; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -49,6 +49,7 @@ | ... | @@ -49,6 +49,7 @@ |
49 | <module>segmentrouting</module> | 49 | <module>segmentrouting</module> |
50 | <module>cordfabric</module> | 50 | <module>cordfabric</module> |
51 | <module>xos-integration</module> | 51 | <module>xos-integration</module> |
52 | + <module>pcep-api</module> | ||
52 | </modules> | 53 | </modules> |
53 | 54 | ||
54 | <properties> | 55 | <properties> | ... | ... |
... | @@ -387,6 +387,11 @@ | ... | @@ -387,6 +387,11 @@ |
387 | 387 | ||
388 | <dependency> | 388 | <dependency> |
389 | <groupId>org.onosproject</groupId> | 389 | <groupId>org.onosproject</groupId> |
390 | + <artifactId>onos-app-pcep-api</artifactId> | ||
391 | + <version>${project.version}</version> | ||
392 | + </dependency> | ||
393 | + <dependency> | ||
394 | + <groupId>org.onosproject</groupId> | ||
390 | <artifactId>onlab-thirdparty</artifactId> | 395 | <artifactId>onlab-thirdparty</artifactId> |
391 | <version>${project.version}</version> | 396 | <version>${project.version}</version> |
392 | </dependency> | 397 | </dependency> | ... | ... |
providers/pcep/app/app.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2015 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 | +<app name="org.onosproject.pcep" origin="ON.Lab" version="${project.version}" | ||
18 | + featuresRepo="mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features" | ||
19 | + features="${project.artifactId}"> | ||
20 | + <description>${project.description}</description> | ||
21 | + <artifact>mvn:${project.groupId}/onos-app-pcep-api/${project.version}</artifact> | ||
22 | + <artifact>mvn:${project.groupId}/onos-pcep-provider-topology/${project.version}</artifact> | ||
23 | + <artifact>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</artifact> | ||
24 | +</app> |
providers/pcep/app/features.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2015 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 | +<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}"> | ||
18 | + <repository>mvn:${project.groupId}/${project.artifactId}/${project.version}/xml/features</repository> | ||
19 | + <feature name="${project.artifactId}" version="${project.version}" | ||
20 | + description="${project.description}"> | ||
21 | + <feature>onos-api</feature> | ||
22 | + <bundle>mvn:${project.groupId}/onos-app-pcep-api/${project.version}</bundle> | ||
23 | + <bundle>mvn:${project.groupId}/onos-pcep-provider-topology/${project.version}</bundle> | ||
24 | + <bundle>mvn:${project.groupId}/onos-pcep-provider-tunnel/${project.version}</bundle> | ||
25 | + </feature> | ||
26 | +</features> |
providers/pcep/app/pom.xml
0 → 100644
1 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
2 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
3 | + <modelVersion>4.0.0</modelVersion> | ||
4 | + <parent> | ||
5 | + <groupId>org.onosproject</groupId> | ||
6 | + <artifactId>onos-pcep-providers</artifactId> | ||
7 | + <version>1.2.0-SNAPSHOT</version> | ||
8 | + <relativePath>../pom.xml</relativePath> | ||
9 | + </parent> | ||
10 | + <artifactId>onos-pcep</artifactId> | ||
11 | + <packaging>pom</packaging> | ||
12 | + <dependencies> | ||
13 | + <dependency> | ||
14 | + <groupId>org.onosproject</groupId> | ||
15 | + <artifactId>onos-app-pcep-api</artifactId> | ||
16 | + </dependency> | ||
17 | + <dependency> | ||
18 | + <groupId>org.onosproject</groupId> | ||
19 | + <artifactId>onos-pcep-provider-topology</artifactId> | ||
20 | + <version>${project.version}</version> | ||
21 | + </dependency> | ||
22 | + <dependency> | ||
23 | + <groupId>org.onosproject</groupId> | ||
24 | + <artifactId>onos-pcep-provider-tunnel</artifactId> | ||
25 | + <version>${project.version}</version> | ||
26 | + </dependency> | ||
27 | + | ||
28 | + </dependencies> | ||
29 | +</project> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
providers/pcep/pom.xml
0 → 100644
1 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
2 | + <modelVersion>4.0.0</modelVersion> | ||
3 | + <parent> | ||
4 | + <groupId>org.onosproject</groupId> | ||
5 | + <artifactId>onos-providers</artifactId> | ||
6 | + <version>1.2.0-SNAPSHOT</version> | ||
7 | + <relativePath>../pom.xml</relativePath> | ||
8 | + </parent> | ||
9 | + <artifactId>onos-pcep-providers</artifactId> | ||
10 | + <packaging>pom</packaging> | ||
11 | + <modules> | ||
12 | + <module>topology</module> | ||
13 | + <module>tunnel</module> | ||
14 | + <module>app</module> | ||
15 | + </modules> | ||
16 | +</project> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
providers/pcep/topology/pom.xml
0 → 100644
1 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
2 | + <modelVersion>4.0.0</modelVersion> | ||
3 | + <parent> | ||
4 | + <groupId>org.onosproject</groupId> | ||
5 | + <artifactId>onos-pcep-providers</artifactId> | ||
6 | + <version>1.2.0-SNAPSHOT</version> | ||
7 | + <relativePath>../pom.xml</relativePath> | ||
8 | + </parent> | ||
9 | + <artifactId>onos-pcep-provider-topology</artifactId> | ||
10 | + <packaging>bundle</packaging> | ||
11 | + <dependencies> | ||
12 | + <dependency> | ||
13 | + <groupId>org.onosproject</groupId> | ||
14 | + <artifactId>onos-app-pcep-api</artifactId> | ||
15 | + </dependency> | ||
16 | + </dependencies> | ||
17 | +</project> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
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.pcep.topology.impl; | ||
17 | + | ||
18 | +import java.util.ArrayList; | ||
19 | +import java.util.HashSet; | ||
20 | +import java.util.List; | ||
21 | +import java.util.Set; | ||
22 | + | ||
23 | +import org.apache.felix.scr.annotations.Activate; | ||
24 | +import org.apache.felix.scr.annotations.Component; | ||
25 | +import org.apache.felix.scr.annotations.Deactivate; | ||
26 | +import org.apache.felix.scr.annotations.Reference; | ||
27 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
28 | +import org.onlab.packet.ChassisId; | ||
29 | +import org.onosproject.cluster.ClusterService; | ||
30 | +import org.onosproject.cluster.NodeId; | ||
31 | +import org.onosproject.mastership.MastershipAdminService; | ||
32 | +import org.onosproject.mastership.MastershipService; | ||
33 | +import org.onosproject.net.ConnectPoint; | ||
34 | +import org.onosproject.net.DefaultAnnotations; | ||
35 | +import org.onosproject.net.Device; | ||
36 | +import org.onosproject.net.DeviceId; | ||
37 | +import org.onosproject.net.Link; | ||
38 | +import org.onosproject.net.Link.Type; | ||
39 | +import org.onosproject.net.MastershipRole; | ||
40 | +import org.onosproject.net.PortNumber; | ||
41 | +import org.onosproject.net.device.DefaultDeviceDescription; | ||
42 | +import org.onosproject.net.device.DefaultPortDescription; | ||
43 | +import org.onosproject.net.device.DeviceDescription; | ||
44 | +import org.onosproject.net.device.DeviceProvider; | ||
45 | +import org.onosproject.net.device.DeviceProviderRegistry; | ||
46 | +import org.onosproject.net.device.DeviceProviderService; | ||
47 | +import org.onosproject.net.device.DeviceService; | ||
48 | +import org.onosproject.net.device.PortDescription; | ||
49 | +import org.onosproject.net.link.DefaultLinkDescription; | ||
50 | +import org.onosproject.net.link.LinkDescription; | ||
51 | +import org.onosproject.net.link.LinkProvider; | ||
52 | +import org.onosproject.net.link.LinkProviderRegistry; | ||
53 | +import org.onosproject.net.link.LinkProviderService; | ||
54 | +import org.onosproject.net.link.LinkService; | ||
55 | +import org.onosproject.net.provider.AbstractProvider; | ||
56 | +import org.onosproject.net.provider.ProviderId; | ||
57 | +import org.onosproject.pcep.api.PcepController; | ||
58 | +import org.onosproject.pcep.api.PcepDpid; | ||
59 | +import org.onosproject.pcep.api.PcepLink; | ||
60 | +import org.onosproject.pcep.api.PcepLinkListener; | ||
61 | +import org.onosproject.pcep.api.PcepOperator.OperationType; | ||
62 | +import org.onosproject.pcep.api.PcepSwitch; | ||
63 | +import org.onosproject.pcep.api.PcepSwitchListener; | ||
64 | +import org.slf4j.Logger; | ||
65 | +import org.slf4j.LoggerFactory; | ||
66 | + | ||
67 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
68 | +import static org.onosproject.net.DeviceId.deviceId; | ||
69 | +import static org.onosproject.pcep.api.PcepDpid.uri; | ||
70 | + | ||
71 | +/** | ||
72 | + * Provider which uses an PCEP controller to detect network infrastructure | ||
73 | + * topology. | ||
74 | + */ | ||
75 | +@Component(immediate = true) | ||
76 | +public class PcepTopologyProvider extends AbstractProvider | ||
77 | + implements LinkProvider, DeviceProvider { | ||
78 | + | ||
79 | + public PcepTopologyProvider() { | ||
80 | + super(new ProviderId("pcep", "org.onosproject.provider.pcep")); | ||
81 | + } | ||
82 | + | ||
83 | + private static final Logger log = LoggerFactory | ||
84 | + .getLogger(PcepTopologyProvider.class); | ||
85 | + | ||
86 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
87 | + protected LinkProviderRegistry linkProviderRegistry; | ||
88 | + | ||
89 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
90 | + protected DeviceProviderRegistry deviceProviderRegistry; | ||
91 | + | ||
92 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
93 | + protected PcepController controller; | ||
94 | + | ||
95 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
96 | + protected DeviceService deviceService; | ||
97 | + | ||
98 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
99 | + protected LinkService linkService; | ||
100 | + | ||
101 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
102 | + protected MastershipAdminService mastershipAdminService; | ||
103 | + | ||
104 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
105 | + protected MastershipService mastershipService; | ||
106 | + | ||
107 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
108 | + protected ClusterService clusterService; | ||
109 | + | ||
110 | + private DeviceProviderService deviceProviderService; | ||
111 | + private LinkProviderService linkProviderService; | ||
112 | + // List<Long> srcportList = new ArrayList<Long>(); | ||
113 | + HashSet<Long> portSet = new HashSet<>(); | ||
114 | + private InternalLinkProvider listener = new InternalLinkProvider(); | ||
115 | + | ||
116 | + @Activate | ||
117 | + public void activate() { | ||
118 | + linkProviderService = linkProviderRegistry.register(this); | ||
119 | + deviceProviderService = deviceProviderRegistry.register(this); | ||
120 | + controller.addListener(listener); | ||
121 | + controller.addLinkListener(listener); | ||
122 | + } | ||
123 | + | ||
124 | + @Deactivate | ||
125 | + public void deactivate() { | ||
126 | + linkProviderRegistry.unregister(this); | ||
127 | + linkProviderService = null; | ||
128 | + controller.removeListener(listener); | ||
129 | + controller.removeLinkListener(listener); | ||
130 | + } | ||
131 | + | ||
132 | + private List<PortDescription> buildPortDescriptions(List<Long> ports, | ||
133 | + String portType) { | ||
134 | + final List<PortDescription> portDescs = new ArrayList<>(); | ||
135 | + for (long port : ports) { | ||
136 | + portDescs.add(buildPortDescription(port, portType)); | ||
137 | + } | ||
138 | + return portDescs; | ||
139 | + } | ||
140 | + | ||
141 | + private PortDescription buildPortDescription(long port, String portType) { | ||
142 | + final PortNumber portNo = PortNumber.portNumber(port); | ||
143 | + final boolean enabled = true; | ||
144 | + DefaultAnnotations extendedAttributes = DefaultAnnotations.builder() | ||
145 | + .set("portType", portType).build(); | ||
146 | + return new DefaultPortDescription(portNo, enabled, extendedAttributes); | ||
147 | + } | ||
148 | + | ||
149 | + /** | ||
150 | + * Build link annotations from pcep link description.the annotations consist | ||
151 | + * of lots of property of Huawei device. | ||
152 | + * | ||
153 | + * @param linkDesc | ||
154 | + * @return | ||
155 | + */ | ||
156 | + private DefaultAnnotations buildLinkAnnotations(PcepLink linkDesc) { | ||
157 | + DefaultAnnotations extendedAttributes = DefaultAnnotations | ||
158 | + .builder() | ||
159 | + .set("subType", String.valueOf(linkDesc.linkSubType())) | ||
160 | + .set("workState", linkDesc.linkState()) | ||
161 | + .set("distance", String.valueOf(linkDesc.linkDistance())) | ||
162 | + .set("capType", linkDesc.linkCapacityType().toLowerCase()) | ||
163 | + .set("avail_" + linkDesc.linkCapacityType().toLowerCase(), | ||
164 | + String.valueOf(linkDesc.linkAvailValue())) | ||
165 | + .set("max_" + linkDesc.linkCapacityType().toLowerCase(), | ||
166 | + String.valueOf(linkDesc.linkMaxValue())).build(); | ||
167 | + | ||
168 | + return extendedAttributes; | ||
169 | + } | ||
170 | + | ||
171 | + /** | ||
172 | + * Build a LinkDescription from a PCEPLink. | ||
173 | + * | ||
174 | + * @param pceLink | ||
175 | + * @return LinkDescription | ||
176 | + */ | ||
177 | + private LinkDescription buildLinkDescription(PcepLink pceLink) { | ||
178 | + LinkDescription ld; | ||
179 | + | ||
180 | + DeviceId srcDeviceID = deviceId(uri(pceLink.linkSrcDeviceID())); | ||
181 | + DeviceId dstDeviceID = deviceId(uri(pceLink.linkDstDeviceId())); | ||
182 | + | ||
183 | + if (deviceService.getDevice(srcDeviceID) == null | ||
184 | + || deviceService.getDevice(dstDeviceID) == null) { | ||
185 | + log.info("the device of the link is not exited" + srcDeviceID | ||
186 | + + dstDeviceID); | ||
187 | + return null; | ||
188 | + } | ||
189 | + // update port info | ||
190 | + long srcPort = pceLink.linkSrcPort(); | ||
191 | + portSet.add(srcPort); | ||
192 | + List<Long> srcportList = new ArrayList<Long>(); | ||
193 | + srcportList.addAll(portSet); | ||
194 | + deviceProviderService | ||
195 | + .updatePorts(srcDeviceID, | ||
196 | + buildPortDescriptions(srcportList, | ||
197 | + pceLink.portType())); | ||
198 | + | ||
199 | + ConnectPoint src = new ConnectPoint(srcDeviceID, | ||
200 | + PortNumber.portNumber(pceLink | ||
201 | + .linkSrcPort())); | ||
202 | + | ||
203 | + ConnectPoint dst = new ConnectPoint(dstDeviceID, | ||
204 | + PortNumber.portNumber(pceLink | ||
205 | + .linkDstPort())); | ||
206 | + DefaultAnnotations extendedAttributes = buildLinkAnnotations(pceLink); | ||
207 | + | ||
208 | + // construct the link | ||
209 | + ld = new DefaultLinkDescription(src, dst, Type.OPTICAL, | ||
210 | + extendedAttributes); | ||
211 | + return ld; | ||
212 | + } | ||
213 | + | ||
214 | + private void processLinkUpdate(LinkDescription linkDescription) { | ||
215 | + | ||
216 | + // dst changed, delete the original link,if the dst device is not in | ||
217 | + // other links ,delete it. | ||
218 | + if (linkService.getLink(linkDescription.src(), linkDescription.dst()) == null) { | ||
219 | + // in face,one src one link | ||
220 | + Set<Link> links = linkService | ||
221 | + .getIngressLinks(linkDescription.src()); | ||
222 | + for (Link link : links) { | ||
223 | + linkProviderService.linkVanished((LinkDescription) link); | ||
224 | + if (linkService.getDeviceLinks(link.dst().deviceId()).size() == 0) { | ||
225 | + deviceProviderService.deviceDisconnected(link.dst() | ||
226 | + .deviceId()); | ||
227 | + } | ||
228 | + } | ||
229 | + | ||
230 | + } | ||
231 | + linkProviderService.linkDetected(linkDescription); | ||
232 | + | ||
233 | + } | ||
234 | + | ||
235 | + private class InternalLinkProvider | ||
236 | + implements PcepSwitchListener, PcepLinkListener { | ||
237 | + | ||
238 | + @Override | ||
239 | + public void switchAdded(PcepDpid dpid) { | ||
240 | + // TODO Auto-generated method stub | ||
241 | + | ||
242 | + if (deviceProviderService == null) { | ||
243 | + return; | ||
244 | + } | ||
245 | + DeviceId devicdId = deviceId(uri(dpid)); | ||
246 | + PcepSwitch sw = controller.getSwitch(dpid); | ||
247 | + checkNotNull(sw, "device should not null."); | ||
248 | + // The default device type is switch. | ||
249 | + Device.Type deviceType = Device.Type.SWITCH; | ||
250 | + ChassisId cId = new ChassisId(dpid.value()); | ||
251 | + | ||
252 | + // Device subType: ROADM,OTN,ROUTER. | ||
253 | + DefaultAnnotations extendedAttributes = DefaultAnnotations | ||
254 | + .builder() | ||
255 | + .set("subType", String.valueOf(sw.getDeviceSubType())) | ||
256 | + .build(); | ||
257 | + | ||
258 | + DeviceDescription description = new DefaultDeviceDescription( | ||
259 | + devicdId.uri(), | ||
260 | + deviceType, | ||
261 | + sw.manufacturerDescription(), | ||
262 | + sw.hardwareDescription(), | ||
263 | + sw.softwareDescription(), | ||
264 | + sw.serialNumber(), | ||
265 | + cId, | ||
266 | + extendedAttributes); | ||
267 | + NodeId localNode = clusterService.getLocalNode().id(); | ||
268 | + mastershipAdminService.setRole(localNode, devicdId, | ||
269 | + MastershipRole.MASTER); | ||
270 | + mastershipService.relinquishMastership(devicdId); | ||
271 | + deviceProviderService.deviceConnected(devicdId, description); | ||
272 | + | ||
273 | + } | ||
274 | + | ||
275 | + @Override | ||
276 | + public void switchRemoved(PcepDpid dpid) { | ||
277 | + // TODO Auto-generated method stub | ||
278 | + | ||
279 | + if (deviceProviderService == null || linkProviderService == null) { | ||
280 | + return; | ||
281 | + } | ||
282 | + deviceProviderService.deviceDisconnected(deviceId(uri(dpid))); | ||
283 | + | ||
284 | + linkProviderService.linksVanished(DeviceId.deviceId(uri(dpid))); | ||
285 | + } | ||
286 | + | ||
287 | + @Override | ||
288 | + public void switchChanged(PcepDpid dpid) { | ||
289 | + // TODO Auto-generated method stub | ||
290 | + | ||
291 | + } | ||
292 | + | ||
293 | + @Override | ||
294 | + public void handlePCEPlink(PcepLink link) { | ||
295 | + | ||
296 | + OperationType operType = link.getOperationType(); | ||
297 | + LinkDescription ld = buildLinkDescription(link); | ||
298 | + if (ld == null) { | ||
299 | + log.error("Invalid link info."); | ||
300 | + return; | ||
301 | + } | ||
302 | + switch (operType) { | ||
303 | + case ADD: | ||
304 | + linkProviderService.linkDetected(ld); | ||
305 | + break; | ||
306 | + case UPDATE: | ||
307 | + processLinkUpdate(ld); | ||
308 | + break; | ||
309 | + | ||
310 | + case DELETE: | ||
311 | + linkProviderService.linkVanished(ld); | ||
312 | + break; | ||
313 | + | ||
314 | + default: | ||
315 | + break; | ||
316 | + | ||
317 | + } | ||
318 | + } | ||
319 | + | ||
320 | + } | ||
321 | + | ||
322 | + @Override | ||
323 | + public void triggerProbe(DeviceId deviceId) { | ||
324 | + // TODO Auto-generated method stub | ||
325 | + | ||
326 | + } | ||
327 | + | ||
328 | + @Override | ||
329 | + public void roleChanged(DeviceId deviceId, MastershipRole newRole) { | ||
330 | + // NodeId localNode = clusterService.getLocalNode().id(); | ||
331 | + // mastershipService.setRole(localNode, deviceId, newRole); | ||
332 | + | ||
333 | + } | ||
334 | + | ||
335 | + @Override | ||
336 | + public boolean isReachable(DeviceId deviceId) { | ||
337 | + // TODO Auto-generated method stub | ||
338 | + return false; | ||
339 | + } | ||
340 | +} |
providers/pcep/topology/src/main/java/org/onosproject/provider/pcep/topology/impl/package-info.java
0 → 100644
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 | + *Provider that uses PCEP controller as a means of infrastructure topology discovery. | ||
18 | + */ | ||
19 | +package org.onosproject.provider.pcep.topology.impl; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
providers/pcep/tunnel/pom.xml
0 → 100644
1 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
2 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
3 | + <modelVersion>4.0.0</modelVersion> | ||
4 | + <parent> | ||
5 | + <groupId>org.onosproject</groupId> | ||
6 | + <artifactId>onos-pcep-providers</artifactId> | ||
7 | + <version>1.2.0-SNAPSHOT</version> | ||
8 | + <relativePath>../pom.xml</relativePath> | ||
9 | + </parent> | ||
10 | + <artifactId>onos-pcep-provider-tunnel</artifactId> | ||
11 | + <packaging>bundle</packaging> | ||
12 | + | ||
13 | + <dependencies> | ||
14 | + <dependency> | ||
15 | + <groupId>org.onosproject</groupId> | ||
16 | + <artifactId>onos-app-pcep-api</artifactId> | ||
17 | + </dependency> | ||
18 | + </dependencies> | ||
19 | +</project> | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
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.pcep.tunnel.impl; | ||
17 | + | ||
18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
19 | +import static org.onosproject.net.DeviceId.deviceId; | ||
20 | +import static org.onosproject.net.PortNumber.portNumber; | ||
21 | +import static org.slf4j.LoggerFactory.getLogger; | ||
22 | + | ||
23 | +import java.util.ArrayList; | ||
24 | +import java.util.HashMap; | ||
25 | +import java.util.List; | ||
26 | +import java.util.Optional; | ||
27 | + | ||
28 | +import org.apache.felix.scr.annotations.Activate; | ||
29 | +import org.apache.felix.scr.annotations.Component; | ||
30 | +import org.apache.felix.scr.annotations.Deactivate; | ||
31 | +import org.apache.felix.scr.annotations.Reference; | ||
32 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
33 | +import org.apache.felix.scr.annotations.Service; | ||
34 | +import org.onosproject.core.DefaultGroupId; | ||
35 | +import org.onosproject.incubator.net.tunnel.DefaultOpticalTunnelEndPoint; | ||
36 | +import org.onosproject.incubator.net.tunnel.DefaultTunnelDescription; | ||
37 | +import org.onosproject.incubator.net.tunnel.OpticalLogicId; | ||
38 | +import org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint; | ||
39 | +import org.onosproject.incubator.net.tunnel.Tunnel; | ||
40 | +import org.onosproject.incubator.net.tunnel.TunnelDescription; | ||
41 | +import org.onosproject.incubator.net.tunnel.TunnelEndPoint; | ||
42 | +import org.onosproject.incubator.net.tunnel.TunnelId; | ||
43 | +import org.onosproject.incubator.net.tunnel.TunnelName; | ||
44 | +import org.onosproject.incubator.net.tunnel.TunnelProvider; | ||
45 | +import org.onosproject.incubator.net.tunnel.TunnelProviderRegistry; | ||
46 | +import org.onosproject.incubator.net.tunnel.TunnelProviderService; | ||
47 | +import org.onosproject.net.ConnectPoint; | ||
48 | +import org.onosproject.net.DefaultAnnotations; | ||
49 | +import org.onosproject.net.DefaultLink; | ||
50 | +import org.onosproject.net.DefaultPath; | ||
51 | +import org.onosproject.net.DeviceId; | ||
52 | +import org.onosproject.net.ElementId; | ||
53 | +import org.onosproject.net.Link; | ||
54 | +import org.onosproject.net.Path; | ||
55 | +import org.onosproject.net.PortNumber; | ||
56 | +import org.onosproject.net.provider.AbstractProvider; | ||
57 | +import org.onosproject.net.provider.ProviderId; | ||
58 | +import org.onosproject.pcep.api.PcepController; | ||
59 | +import org.onosproject.pcep.api.PcepDpid; | ||
60 | +import org.onosproject.pcep.api.PcepHopNodeDescription; | ||
61 | +import org.onosproject.pcep.api.PcepOperator.OperationType; | ||
62 | +import org.onosproject.pcep.api.PcepTunnel; | ||
63 | +import org.onosproject.pcep.api.PcepTunnel.PATHTYPE; | ||
64 | +import org.onosproject.pcep.api.PcepTunnelListener; | ||
65 | +import org.slf4j.Logger; | ||
66 | + | ||
67 | +import static org.onosproject.pcep.api.PcepDpid.*; | ||
68 | + | ||
69 | +/** | ||
70 | + * Provider which uses an PCEP controller to detect, update, create network | ||
71 | + * tunnels. | ||
72 | + */ | ||
73 | +@Component(immediate = true) | ||
74 | +@Service | ||
75 | +public class PcepTunnelProvider extends AbstractProvider | ||
76 | + implements TunnelProvider { | ||
77 | + | ||
78 | + private static final Logger log = getLogger(PcepTunnelProvider.class); | ||
79 | + private static final long MAX_BANDWIDTH = 99999744; | ||
80 | + private static final long MIN_BANDWIDTH = 64; | ||
81 | + static final String PROVIDER_ID = "org.onosproject.provider.tunnel.default"; | ||
82 | + | ||
83 | + private static final String TUNNLE_NOT_NULL = "Create failed,The given port may be wrong or has been occupied."; | ||
84 | + | ||
85 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
86 | + protected TunnelProviderRegistry tunnelProviderRegistry; | ||
87 | + | ||
88 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
89 | + protected PcepController controller; | ||
90 | + | ||
91 | + TunnelProviderService service; | ||
92 | + | ||
93 | + HashMap<String, TunnelId> tunnelMap = new HashMap<String, TunnelId>(); | ||
94 | + | ||
95 | + private InnerTunnerProvider listener = new InnerTunnerProvider(); | ||
96 | + | ||
97 | + /** | ||
98 | + * Creates a Tunnel provider. | ||
99 | + */ | ||
100 | + public PcepTunnelProvider() { | ||
101 | + super(new ProviderId("default", PROVIDER_ID)); | ||
102 | + } | ||
103 | + | ||
104 | + @Activate | ||
105 | + public void activate() { | ||
106 | + service = tunnelProviderRegistry.register(this); | ||
107 | + controller.addTunnelListener(listener); | ||
108 | + log.info("Started"); | ||
109 | + } | ||
110 | + | ||
111 | + @Deactivate | ||
112 | + public void deactivate() { | ||
113 | + tunnelProviderRegistry.unregister(this); | ||
114 | + controller.removeTunnelListener(listener); | ||
115 | + log.info("Stopped"); | ||
116 | + } | ||
117 | + | ||
118 | + @Override | ||
119 | + public void setupTunnel(Tunnel tunnel, Path path) { | ||
120 | + // TODO Auto-generated method stub | ||
121 | + | ||
122 | + } | ||
123 | + | ||
124 | + @Override | ||
125 | + public void setupTunnel(ElementId srcElement, Tunnel tunnel, Path path) { | ||
126 | + // TODO Auto-generated method stub | ||
127 | + | ||
128 | + } | ||
129 | + | ||
130 | + @Override | ||
131 | + public void releaseTunnel(Tunnel tunnel) { | ||
132 | + // TODO Auto-generated method stub | ||
133 | + | ||
134 | + } | ||
135 | + | ||
136 | + @Override | ||
137 | + public void releaseTunnel(ElementId srcElement, Tunnel tunnel) { | ||
138 | + // TODO Auto-generated method stub | ||
139 | + | ||
140 | + } | ||
141 | + | ||
142 | + @Override | ||
143 | + public void updateTunnel(Tunnel tunnel, Path path) { | ||
144 | + // TODO Auto-generated method stub | ||
145 | + | ||
146 | + } | ||
147 | + | ||
148 | + @Override | ||
149 | + public void updateTunnel(ElementId srcElement, Tunnel tunnel, Path path) { | ||
150 | + // TODO Auto-generated method stub | ||
151 | + | ||
152 | + } | ||
153 | + | ||
154 | + @Override | ||
155 | + public TunnelId tunnelAdded(TunnelDescription tunnel) { | ||
156 | + | ||
157 | + long bandwidth = Long.parseLong(tunnel.annotations().value("bandWith")); | ||
158 | + | ||
159 | + if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) { | ||
160 | + System.out.println("Update failed, invalid bandwidth."); | ||
161 | + return null; | ||
162 | + } | ||
163 | + | ||
164 | + // endpoints | ||
165 | + OpticalTunnelEndPoint src = (org.onosproject.incubator.net.tunnel.OpticalTunnelEndPoint) tunnel | ||
166 | + .src(); | ||
167 | + OpticalTunnelEndPoint dst = (OpticalTunnelEndPoint) tunnel.dst(); | ||
168 | + // devices | ||
169 | + DeviceId srcId = (DeviceId) src.elementId().get(); | ||
170 | + DeviceId dstId = (DeviceId) dst.elementId().get(); | ||
171 | + | ||
172 | + // ports | ||
173 | + long srcPort = src.portNumber().get().toLong(); | ||
174 | + long dstPort = dst.portNumber().get().toLong(); | ||
175 | + | ||
176 | + // type | ||
177 | + if (tunnel.type() != Tunnel.Type.VLAN) { | ||
178 | + System.out | ||
179 | + .println("Llegal tunnel type. Only support VLAN tunnel creation."); | ||
180 | + return null; | ||
181 | + } | ||
182 | + | ||
183 | + PcepTunnel pcepTunnel = controller.applyTunnel(srcId, dstId, srcPort, | ||
184 | + dstPort, bandwidth, | ||
185 | + tunnel.tunnelName() | ||
186 | + .value()); | ||
187 | + | ||
188 | + checkNotNull(pcepTunnel, TUNNLE_NOT_NULL); | ||
189 | + TunnelDescription tunnelAdded = buildOpticalTunnel(pcepTunnel, null); | ||
190 | + TunnelId tunnelId = service.tunnelAdded(tunnelAdded); | ||
191 | + | ||
192 | + tunnelMap.put(String.valueOf(pcepTunnel.id()), tunnelId); | ||
193 | + return tunnelId; | ||
194 | + } | ||
195 | + | ||
196 | + @Override | ||
197 | + public void tunnelRemoved(TunnelDescription tunnel) { | ||
198 | + Tunnel tunnelOld = tunnelQueryById(tunnel.id()); | ||
199 | + checkNotNull(tunnelOld, "The tunnel id is not exsited."); | ||
200 | + if (tunnelOld.type() != Tunnel.Type.VLAN) { | ||
201 | + System.out | ||
202 | + .println("Llegal tunnel type. Only support VLAN tunnel deletion."); | ||
203 | + return; | ||
204 | + } | ||
205 | + String pcepTunnelId = getPCEPTunnelKey(tunnel.id()); | ||
206 | + checkNotNull(pcepTunnelId, "The tunnel id is not exsited."); | ||
207 | + if (controller.deleteTunnel(pcepTunnelId)) { | ||
208 | + log.info("delete tunnel:" + pcepTunnelId + "ok."); | ||
209 | + } | ||
210 | + tunnelMap.remove(pcepTunnelId); | ||
211 | + service.tunnelRemoved(tunnel); | ||
212 | + | ||
213 | + } | ||
214 | + | ||
215 | + @Override | ||
216 | + public void tunnelUpdated(TunnelDescription tunnel) { | ||
217 | + | ||
218 | + Tunnel tunnelOld = tunnelQueryById(tunnel.id()); | ||
219 | + if (tunnelOld.type() != Tunnel.Type.VLAN) { | ||
220 | + System.out | ||
221 | + .println("Llegal tunnel type. Only support VLAN tunnel update."); | ||
222 | + return; | ||
223 | + } | ||
224 | + long bandwidth = Long.parseLong(tunnel.annotations().value("bandWith")); | ||
225 | + if (bandwidth < MIN_BANDWIDTH || bandwidth > MAX_BANDWIDTH) { | ||
226 | + System.out.println("Update failed, invalid bandwidth."); | ||
227 | + return; | ||
228 | + } | ||
229 | + String pcepTunnelId = getPCEPTunnelKey(tunnel.id()); | ||
230 | + | ||
231 | + checkNotNull(pcepTunnelId, "Invalid tunnel id"); | ||
232 | + if (!controller.updateTunnelBandwidth(pcepTunnelId, bandwidth)) { | ||
233 | + | ||
234 | + System.out.println("Update failed,maybe invalid bandwidth."); | ||
235 | + return; | ||
236 | + | ||
237 | + } | ||
238 | + service.tunnelUpdated(tunnel); | ||
239 | + } | ||
240 | + | ||
241 | + // Short-hand for creating a connection point. | ||
242 | + private ConnectPoint connectPoint(PcepDpid id, long port) { | ||
243 | + return new ConnectPoint(deviceId(uri(id)), portNumber(port)); | ||
244 | + } | ||
245 | + | ||
246 | + // Short-hand for creating a link. | ||
247 | + private Link link(PcepDpid src, long sp, PcepDpid dst, long dp) { | ||
248 | + return new DefaultLink(id(), connectPoint(src, sp), connectPoint(dst, | ||
249 | + dp), | ||
250 | + Link.Type.TUNNEL); | ||
251 | + } | ||
252 | + | ||
253 | + // Creates a path that leads through the given devices. | ||
254 | + private Path createPath(List<PcepHopNodeDescription> hopList, | ||
255 | + PATHTYPE pathtype) { | ||
256 | + if (hopList == null || hopList.size() == 0) { | ||
257 | + return null; | ||
258 | + } | ||
259 | + List<Link> links = new ArrayList<>(); | ||
260 | + for (int i = 1; i < hopList.size() - 1; i = i + 2) { | ||
261 | + links.add(link(hopList.get(i).getDeviceId(), hopList.get(i) | ||
262 | + .getPortNum(), hopList.get(i + 1).getDeviceId(), hopList | ||
263 | + .get(i + 1).getPortNum())); | ||
264 | + } | ||
265 | + | ||
266 | + int hopNum = hopList.size() - 2; | ||
267 | + DefaultAnnotations extendAnnotations = DefaultAnnotations.builder() | ||
268 | + .set("pathNum", String.valueOf(hopNum)) | ||
269 | + .set("pathType", String.valueOf(pathtype)).build(); | ||
270 | + return new DefaultPath(id(), links, hopNum, extendAnnotations); | ||
271 | + } | ||
272 | + | ||
273 | + // convert the path description to a string. | ||
274 | + public String pathToString(List<Link> links) { | ||
275 | + StringBuilder builder = new StringBuilder(); | ||
276 | + builder.append("{"); | ||
277 | + for (Link link : links) { | ||
278 | + builder.append("(Device:" + link.src().deviceId() + " Port:" | ||
279 | + + link.src().port().toLong()); | ||
280 | + builder.append(" Device:" + link.dst().deviceId() + " Port:" | ||
281 | + + link.dst().port().toLong()); | ||
282 | + builder.append(")"); | ||
283 | + } | ||
284 | + builder.append("}"); | ||
285 | + return builder.toString(); | ||
286 | + } | ||
287 | + | ||
288 | + // build a TunnelDescription. | ||
289 | + private TunnelDescription buildOpticalTunnel(PcepTunnel pcepTunnel, | ||
290 | + TunnelId tunnelId) { | ||
291 | + TunnelEndPoint srcPoint = null; | ||
292 | + TunnelEndPoint dstPoint = null; | ||
293 | + Tunnel.Type tunnelType = null; | ||
294 | + TunnelName name = TunnelName.tunnelName(pcepTunnel.name()); | ||
295 | + | ||
296 | + // add path after codes of tunnel's path merged | ||
297 | + Path path = createPath(pcepTunnel.getHopList(), | ||
298 | + pcepTunnel.getPathType()); | ||
299 | + | ||
300 | + OpticalTunnelEndPoint.Type endPointType = null; | ||
301 | + switch (pcepTunnel.type()) { | ||
302 | + case OCH: | ||
303 | + tunnelType = Tunnel.Type.OCH; | ||
304 | + endPointType = OpticalTunnelEndPoint.Type.LAMBDA; | ||
305 | + break; | ||
306 | + | ||
307 | + case OTN: | ||
308 | + tunnelType = Tunnel.Type.ODUK; | ||
309 | + endPointType = OpticalTunnelEndPoint.Type.TIMESLOT; | ||
310 | + break; | ||
311 | + | ||
312 | + case UNI: | ||
313 | + tunnelType = Tunnel.Type.VLAN; | ||
314 | + endPointType = null; | ||
315 | + break; | ||
316 | + | ||
317 | + default: | ||
318 | + break; | ||
319 | + } | ||
320 | + DeviceId srcDid = deviceId(uri(pcepTunnel.srcDeviceID())); | ||
321 | + DeviceId dstDid = deviceId(uri(pcepTunnel.dstDeviceId())); | ||
322 | + PortNumber srcPort = PortNumber.portNumber(pcepTunnel.srcPort()); | ||
323 | + PortNumber dstPort = PortNumber.portNumber(pcepTunnel.dstPort()); | ||
324 | + | ||
325 | + srcPoint = new DefaultOpticalTunnelEndPoint(id(), Optional.of(srcDid), | ||
326 | + Optional.of(srcPort), null, | ||
327 | + endPointType, | ||
328 | + OpticalLogicId.logicId(0), | ||
329 | + true); | ||
330 | + dstPoint = new DefaultOpticalTunnelEndPoint(id(), Optional.of(dstDid), | ||
331 | + Optional.of(dstPort), null, | ||
332 | + endPointType, | ||
333 | + OpticalLogicId.logicId(0), | ||
334 | + true); | ||
335 | + | ||
336 | + // basic annotations | ||
337 | + DefaultAnnotations annotations = DefaultAnnotations.builder() | ||
338 | + .set("bandWith", String.valueOf(pcepTunnel.bandWidth())) | ||
339 | + .set("SLA", String.valueOf(pcepTunnel.getSla())) | ||
340 | + .set("index", String.valueOf(pcepTunnel.id())).build(); | ||
341 | + | ||
342 | + // if (path != null) { | ||
343 | + // | ||
344 | + // DefaultAnnotations extendAnnotations = DefaultAnnotations.builder() | ||
345 | + // .set("pathNum", String.valueOf(hopNum)) | ||
346 | + // // .set("path", pathString) | ||
347 | + // .set("pathType", String.valueOf(pcepTunnel.getPathType())) | ||
348 | + // .build(); | ||
349 | + // annotations = DefaultAnnotations.merge(annotations, | ||
350 | + // extendAnnotations); | ||
351 | + // } | ||
352 | + | ||
353 | + // a VLAN tunnel always carry OCH tunnel, this annotation is the index | ||
354 | + // of a OCH tunnel. | ||
355 | + if (pcepTunnel.underLayTunnelId() != 0) { | ||
356 | + DefaultAnnotations extendAnnotations = DefaultAnnotations | ||
357 | + .builder() | ||
358 | + .set("underLayTunnelIndex", | ||
359 | + String.valueOf(pcepTunnel.underLayTunnelId())).build(); | ||
360 | + annotations = DefaultAnnotations.merge(annotations, | ||
361 | + extendAnnotations); | ||
362 | + | ||
363 | + } | ||
364 | + TunnelDescription tunnel = new DefaultTunnelDescription( | ||
365 | + tunnelId, | ||
366 | + srcPoint, | ||
367 | + dstPoint, | ||
368 | + tunnelType, | ||
369 | + new DefaultGroupId( | ||
370 | + 0), | ||
371 | + id(), name, | ||
372 | + path, | ||
373 | + annotations); | ||
374 | + return tunnel; | ||
375 | + | ||
376 | + } | ||
377 | + | ||
378 | + /** | ||
379 | + * Get the tunnelID according to the tunnel key. | ||
380 | + * | ||
381 | + * @param tunnelKey tunnel key | ||
382 | + * @return corresponding tunnel id of the a tunnel key. | ||
383 | + */ | ||
384 | + private TunnelId getTunnelId(String tunnelKey) { | ||
385 | + | ||
386 | + for (String key : tunnelMap.keySet()) { | ||
387 | + if (key.equals(tunnelKey)) { | ||
388 | + return tunnelMap.get(key); | ||
389 | + } | ||
390 | + } | ||
391 | + return null; | ||
392 | + } | ||
393 | + | ||
394 | + /** | ||
395 | + * Get the tunnel key according to the tunnelID. | ||
396 | + * | ||
397 | + * @param tunnelId tunnel id | ||
398 | + * @return corresponding a tunnel key of the tunnel id. | ||
399 | + */ | ||
400 | + private String getPCEPTunnelKey(TunnelId tunnelId) { | ||
401 | + for (String key : tunnelMap.keySet()) { | ||
402 | + if (tunnelMap.get(key).id() == tunnelId.id()) { | ||
403 | + return key; | ||
404 | + } | ||
405 | + } | ||
406 | + return null; | ||
407 | + | ||
408 | + } | ||
409 | + | ||
410 | + private class InnerTunnerProvider implements PcepTunnelListener { | ||
411 | + | ||
412 | + @Override | ||
413 | + public void handlePCEPTunnel(PcepTunnel pcepTunnel) { | ||
414 | + | ||
415 | + TunnelDescription tunnel = null; | ||
416 | + // instance and id identify a tunnel together | ||
417 | + String tunnelKey = String.valueOf(pcepTunnel.getInstance()) | ||
418 | + + String.valueOf(pcepTunnel.id()); | ||
419 | + | ||
420 | + if (tunnelKey == null || "".equals(tunnelKey)) { | ||
421 | + log.error("Invalid PCEP tunnel"); | ||
422 | + return; | ||
423 | + } | ||
424 | + | ||
425 | + TunnelId tunnelId = getTunnelId(tunnelKey); | ||
426 | + | ||
427 | + tunnel = buildOpticalTunnel(pcepTunnel, tunnelId); | ||
428 | + | ||
429 | + OperationType operType = pcepTunnel.getOperationType(); | ||
430 | + switch (operType) { | ||
431 | + case ADD: | ||
432 | + tunnelId = service.tunnelAdded(tunnel); | ||
433 | + tunnelMap.put(tunnelKey, tunnelId); | ||
434 | + break; | ||
435 | + | ||
436 | + case UPDATE: | ||
437 | + service.tunnelUpdated(tunnel); | ||
438 | + break; | ||
439 | + | ||
440 | + case DELETE: | ||
441 | + service.tunnelRemoved(tunnel); | ||
442 | + tunnelMap.remove(tunnelKey); | ||
443 | + break; | ||
444 | + | ||
445 | + default: | ||
446 | + log.error("Invalid tunnel operation"); | ||
447 | + | ||
448 | + } | ||
449 | + | ||
450 | + } | ||
451 | + } | ||
452 | + | ||
453 | + @Override | ||
454 | + public Tunnel tunnelQueryById(TunnelId tunnelId) { | ||
455 | + return service.tunnelQueryById(tunnelId); | ||
456 | + } | ||
457 | + | ||
458 | +} |
providers/pcep/tunnel/src/main/java/org/onosproject/provider/pcep/tunnel/impl/package-info.java
0 → 100644
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 | + *Provider that uses PCEP controller as a means of infrastructure tunnel discovery. | ||
18 | + */ | ||
19 | +package org.onosproject.provider.pcep.tunnel.impl; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
... | @@ -38,6 +38,7 @@ | ... | @@ -38,6 +38,7 @@ |
38 | <module>netconf</module> | 38 | <module>netconf</module> |
39 | <module>null</module> | 39 | <module>null</module> |
40 | <module>tunnel</module> | 40 | <module>tunnel</module> |
41 | + <module>pcep</module> | ||
41 | </modules> | 42 | </modules> |
42 | 43 | ||
43 | <dependencies> | 44 | <dependencies> | ... | ... |
-
Please register or login to post a comment