blob: 2df0ee6cbd2180f4ef7a63c6cca848ca47f9cf3a [file] [log] [blame]
Phaneendra Manda0c423422016-04-19 00:31:53 +05301/*
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 */
16package org.onosproject.vtnrsc.portchainsfmap.impl;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19import static org.slf4j.LoggerFactory.getLogger;
20
21import java.util.List;
22import java.util.ListIterator;
23
24import org.apache.felix.scr.annotations.Activate;
25import org.apache.felix.scr.annotations.Component;
26import org.apache.felix.scr.annotations.Deactivate;
27import org.apache.felix.scr.annotations.Reference;
28import org.apache.felix.scr.annotations.ReferenceCardinality;
29import org.apache.felix.scr.annotations.Service;
30import org.onosproject.vtnrsc.PortChain;
31import org.onosproject.vtnrsc.PortChainId;
32import org.onosproject.vtnrsc.PortPairGroup;
33import org.onosproject.vtnrsc.PortPairGroupId;
34import org.onosproject.vtnrsc.ServiceFunctionGroup;
35import org.onosproject.vtnrsc.portchain.PortChainService;
36import org.onosproject.vtnrsc.portchainsfmap.PortChainSfMapService;
37import org.onosproject.vtnrsc.portpair.PortPairService;
38import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService;
39import org.slf4j.Logger;
40
41import 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
50public 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}