Committed by
Gerrit Code Review
[ONOS-4226]Portchain to service function map interface
Change-Id: Ie49d2b6755bf5ee92b40e09755a3ae675c47e31d
Showing
7 changed files
with
211 additions
and
11 deletions
... | @@ -24,6 +24,7 @@ import java.util.Objects; | ... | @@ -24,6 +24,7 @@ import java.util.Objects; |
24 | import java.util.concurrent.ConcurrentHashMap; | 24 | import java.util.concurrent.ConcurrentHashMap; |
25 | 25 | ||
26 | import com.google.common.collect.ImmutableList; | 26 | import com.google.common.collect.ImmutableList; |
27 | +import com.google.common.collect.ImmutableMap; | ||
27 | 28 | ||
28 | /** | 29 | /** |
29 | * Implementation of port pair group. | 30 | * Implementation of port pair group. |
... | @@ -99,6 +100,11 @@ public final class DefaultPortPairGroup implements PortPairGroup { | ... | @@ -99,6 +100,11 @@ public final class DefaultPortPairGroup implements PortPairGroup { |
99 | } | 100 | } |
100 | 101 | ||
101 | @Override | 102 | @Override |
103 | + public Map<PortPairId, Integer> portPairLoadMap() { | ||
104 | + return ImmutableMap.copyOf(portPairLoadMap); | ||
105 | + } | ||
106 | + | ||
107 | + @Override | ||
102 | public int hashCode() { | 108 | public int hashCode() { |
103 | return Objects.hash(portPairGroupId, tenantId, name, description, | 109 | return Objects.hash(portPairGroupId, tenantId, name, description, |
104 | portPairList); | 110 | portPairList); | ... | ... |
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | package org.onosproject.vtnrsc; | 16 | package org.onosproject.vtnrsc; |
17 | 17 | ||
18 | import java.util.List; | 18 | import java.util.List; |
19 | +import java.util.Map; | ||
19 | 20 | ||
20 | /** | 21 | /** |
21 | * Abstraction of an entity providing Port Pair Group information. | 22 | * Abstraction of an entity providing Port Pair Group information. |
... | @@ -63,7 +64,7 @@ public interface PortPairGroup { | ... | @@ -63,7 +64,7 @@ public interface PortPairGroup { |
63 | * | 64 | * |
64 | * @param portPairId port pair id. | 65 | * @param portPairId port pair id. |
65 | */ | 66 | */ |
66 | - public void addLoad(PortPairId portPairId); | 67 | + void addLoad(PortPairId portPairId); |
67 | 68 | ||
68 | /** | 69 | /** |
69 | * Get the load on the given port pair id. | 70 | * Get the load on the given port pair id. |
... | @@ -71,7 +72,14 @@ public interface PortPairGroup { | ... | @@ -71,7 +72,14 @@ public interface PortPairGroup { |
71 | * @param portPairId port pair id | 72 | * @param portPairId port pair id |
72 | * @return load on the given port pair id. | 73 | * @return load on the given port pair id. |
73 | */ | 74 | */ |
74 | - public int getLoad(PortPairId portPairId); | 75 | + int getLoad(PortPairId portPairId); |
76 | + | ||
77 | + /** | ||
78 | + * Get the map of port pair id and its load. | ||
79 | + * | ||
80 | + * @return port pair and load map | ||
81 | + */ | ||
82 | + Map<PortPairId, Integer> portPairLoadMap(); | ||
75 | 83 | ||
76 | /** | 84 | /** |
77 | * Returns whether this port pair group is an exact match to the | 85 | * Returns whether this port pair group is an exact match to the | ... | ... |
apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchainsfmap/PortChainSfMapService.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present 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.vtnrsc.portchainsfmap; | ||
17 | + | ||
18 | +import java.util.List; | ||
19 | + | ||
20 | +import org.onosproject.vtnrsc.PortChainId; | ||
21 | +import org.onosproject.vtnrsc.ServiceFunctionGroup; | ||
22 | + | ||
23 | +/** | ||
24 | + * Service for interacting with the inventory of service functions for a given port chain. | ||
25 | + */ | ||
26 | +public interface PortChainSfMapService { | ||
27 | + | ||
28 | + /** | ||
29 | + * Returns true if the port chain exists. | ||
30 | + * | ||
31 | + * @param portChainId port chain identifier | ||
32 | + * @return true or false if one with the given identifier exists. | ||
33 | + */ | ||
34 | + boolean exists(PortChainId portChainId); | ||
35 | + | ||
36 | + /** | ||
37 | + * Returns the list of service function groups available in the given port chain. | ||
38 | + * | ||
39 | + * @param portChainId port chain id | ||
40 | + * @return list of service functions | ||
41 | + */ | ||
42 | + List<ServiceFunctionGroup> getServiceFunctions(PortChainId portChainId); | ||
43 | + | ||
44 | +} |
apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchainsfmap/impl/PortChainSfMapManager.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-present 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.vtnrsc.portchainsfmap.impl; | ||
17 | + | ||
18 | +import static com.google.common.base.Preconditions.checkNotNull; | ||
19 | +import static org.slf4j.LoggerFactory.getLogger; | ||
20 | + | ||
21 | +import java.util.List; | ||
22 | +import java.util.ListIterator; | ||
23 | + | ||
24 | +import org.apache.felix.scr.annotations.Activate; | ||
25 | +import org.apache.felix.scr.annotations.Component; | ||
26 | +import org.apache.felix.scr.annotations.Deactivate; | ||
27 | +import org.apache.felix.scr.annotations.Reference; | ||
28 | +import org.apache.felix.scr.annotations.ReferenceCardinality; | ||
29 | +import org.apache.felix.scr.annotations.Service; | ||
30 | +import org.onosproject.vtnrsc.PortChain; | ||
31 | +import org.onosproject.vtnrsc.PortChainId; | ||
32 | +import org.onosproject.vtnrsc.PortPairGroup; | ||
33 | +import org.onosproject.vtnrsc.PortPairGroupId; | ||
34 | +import org.onosproject.vtnrsc.ServiceFunctionGroup; | ||
35 | +import org.onosproject.vtnrsc.portchain.PortChainService; | ||
36 | +import org.onosproject.vtnrsc.portchainsfmap.PortChainSfMapService; | ||
37 | +import org.onosproject.vtnrsc.portpair.PortPairService; | ||
38 | +import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService; | ||
39 | +import org.slf4j.Logger; | ||
40 | + | ||
41 | +import com.google.common.collect.Lists; | ||
42 | + | ||
43 | +/** | ||
44 | + * Provides implementation of the PortChainSfMapService. | ||
45 | + * A port pair group is nothing but group of similar service functions. | ||
46 | + * A port pair is nothing but a service function. | ||
47 | + */ | ||
48 | +@Component(immediate = true) | ||
49 | +@Service | ||
50 | +public class PortChainSfMapManager implements PortChainSfMapService { | ||
51 | + | ||
52 | + private static final String PORT_CHAIN_ID_NULL = "PortChain ID cannot be null"; | ||
53 | + | ||
54 | + private final Logger log = getLogger(getClass()); | ||
55 | + | ||
56 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
57 | + protected PortChainService portChainService; | ||
58 | + | ||
59 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
60 | + protected PortPairGroupService portPairGroupService; | ||
61 | + | ||
62 | + @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
63 | + protected PortPairService portPairService; | ||
64 | + | ||
65 | + @Activate | ||
66 | + public void activate() { | ||
67 | + log.info("Started"); | ||
68 | + } | ||
69 | + | ||
70 | + @Deactivate | ||
71 | + public void deactivate() { | ||
72 | + log.info("Stopped"); | ||
73 | + } | ||
74 | + | ||
75 | + @Override | ||
76 | + public boolean exists(PortChainId portChainId) { | ||
77 | + checkNotNull(portChainId, PORT_CHAIN_ID_NULL); | ||
78 | + return portChainService.exists(portChainId); | ||
79 | + } | ||
80 | + | ||
81 | + @Override | ||
82 | + public List<ServiceFunctionGroup> getServiceFunctions(PortChainId portChainId) { | ||
83 | + List<ServiceFunctionGroup> serviceFunctionGroupList = Lists.newArrayList(); | ||
84 | + PortChain portChain = portChainService.getPortChain(portChainId); | ||
85 | + // Go through the port pair group list | ||
86 | + List<PortPairGroupId> portPairGrpList = portChain.portPairGroups(); | ||
87 | + ListIterator<PortPairGroupId> listGrpIterator = portPairGrpList.listIterator(); | ||
88 | + | ||
89 | + while (listGrpIterator.next() != null) { | ||
90 | + PortPairGroupId portPairGroupId = listGrpIterator.next(); | ||
91 | + PortPairGroup portPairGroup = portPairGroupService.getPortPairGroup(portPairGroupId); | ||
92 | + ServiceFunctionGroup sfg = new ServiceFunctionGroup(portPairGroup.name(), portPairGroup.description(), | ||
93 | + portPairGroup.portPairLoadMap()); | ||
94 | + serviceFunctionGroupList.add(sfg); | ||
95 | + } | ||
96 | + return serviceFunctionGroupList; | ||
97 | + } | ||
98 | +} |
apps/vtn/vtnrsc/src/main/java/org/onosproject/vtnrsc/portchainsfmap/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 | +/** | ||
18 | + * Service for interacting with the inventory of port chains to get details of service functions and stats. | ||
19 | + */ | ||
20 | +package org.onosproject.vtnrsc.portchainsfmap.impl; |
1 | +/* | ||
2 | + * Copyright 2016-present 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 | + * Service for interacting with the inventory of port chains to get details of service functions and stats. | ||
19 | + */ | ||
20 | +package org.onosproject.vtnrsc.portchainsfmap; |
... | @@ -19,6 +19,7 @@ import com.eclipsesource.json.Json; | ... | @@ -19,6 +19,7 @@ import com.eclipsesource.json.Json; |
19 | import com.eclipsesource.json.JsonObject; | 19 | import com.eclipsesource.json.JsonObject; |
20 | import com.google.common.collect.ImmutableList; | 20 | import com.google.common.collect.ImmutableList; |
21 | import com.google.common.collect.Lists; | 21 | import com.google.common.collect.Lists; |
22 | +import java.util.Map; | ||
22 | import org.junit.After; | 23 | import org.junit.After; |
23 | import org.junit.Before; | 24 | import org.junit.Before; |
24 | import org.junit.Test; | 25 | import org.junit.Test; |
... | @@ -116,22 +117,25 @@ public class PortPairGroupResourceTest extends VtnResourceTest { | ... | @@ -116,22 +117,25 @@ public class PortPairGroupResourceTest extends VtnResourceTest { |
116 | } | 117 | } |
117 | 118 | ||
118 | @Override | 119 | @Override |
119 | - public boolean exactMatch(PortPairGroup portPairGroup) { | ||
120 | - return this.equals(portPairGroup) && | ||
121 | - Objects.equals(this.portPairGroupId, portPairGroup.portPairGroupId()) && | ||
122 | - Objects.equals(this.tenantId, portPairGroup.tenantId()); | ||
123 | - } | ||
124 | - | ||
125 | - @Override | ||
126 | public void addLoad(PortPairId portPairId) { | 120 | public void addLoad(PortPairId portPairId) { |
127 | - // TODO Auto-generated method stub | ||
128 | } | 121 | } |
129 | 122 | ||
130 | @Override | 123 | @Override |
131 | public int getLoad(PortPairId portPairId) { | 124 | public int getLoad(PortPairId portPairId) { |
132 | - // TODO Auto-generated method stub | ||
133 | return 0; | 125 | return 0; |
134 | } | 126 | } |
127 | + | ||
128 | + @Override | ||
129 | + public Map<PortPairId, Integer> portPairLoadMap() { | ||
130 | + return null; | ||
131 | + } | ||
132 | + | ||
133 | + @Override | ||
134 | + public boolean exactMatch(PortPairGroup portPairGroup) { | ||
135 | + return this.equals(portPairGroup) && | ||
136 | + Objects.equals(this.portPairGroupId, portPairGroup.portPairGroupId()) && | ||
137 | + Objects.equals(this.tenantId, portPairGroup.tenantId()); | ||
138 | + } | ||
135 | } | 139 | } |
136 | 140 | ||
137 | /** | 141 | /** | ... | ... |
-
Please register or login to post a comment