Phaneendra Manda | 0c42342 | 2016-04-19 00:31:53 +0530 | [diff] [blame^] | 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 | } |