Phaneendra Manda | 0c42342 | 2016-04-19 00:31:53 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Phaneendra Manda | 0c42342 | 2016-04-19 00:31:53 +0530 | [diff] [blame] | 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 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
| 19 | import com.google.common.collect.Lists; |
Phaneendra Manda | 0c42342 | 2016-04-19 00:31:53 +0530 | [diff] [blame] | 20 | import org.onosproject.vtnrsc.PortChain; |
| 21 | import org.onosproject.vtnrsc.PortChainId; |
| 22 | import org.onosproject.vtnrsc.PortPairGroup; |
| 23 | import org.onosproject.vtnrsc.PortPairGroupId; |
| 24 | import org.onosproject.vtnrsc.ServiceFunctionGroup; |
| 25 | import org.onosproject.vtnrsc.portchain.PortChainService; |
| 26 | import org.onosproject.vtnrsc.portchainsfmap.PortChainSfMapService; |
| 27 | import org.onosproject.vtnrsc.portpair.PortPairService; |
| 28 | import org.onosproject.vtnrsc.portpairgroup.PortPairGroupService; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 29 | import org.osgi.service.component.annotations.Activate; |
| 30 | import org.osgi.service.component.annotations.Component; |
| 31 | import org.osgi.service.component.annotations.Deactivate; |
| 32 | import org.osgi.service.component.annotations.Reference; |
| 33 | import org.osgi.service.component.annotations.ReferenceCardinality; |
Phaneendra Manda | 0c42342 | 2016-04-19 00:31:53 +0530 | [diff] [blame] | 34 | import org.slf4j.Logger; |
| 35 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 36 | import java.util.List; |
| 37 | import java.util.ListIterator; |
| 38 | |
| 39 | import static com.google.common.base.Preconditions.checkNotNull; |
| 40 | import static org.slf4j.LoggerFactory.getLogger; |
Phaneendra Manda | 0c42342 | 2016-04-19 00:31:53 +0530 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Provides implementation of the PortChainSfMapService. |
| 44 | * A port pair group is nothing but group of similar service functions. |
| 45 | * A port pair is nothing but a service function. |
| 46 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 47 | @Component(immediate = true, service = PortChainSfMapService.class) |
Phaneendra Manda | 0c42342 | 2016-04-19 00:31:53 +0530 | [diff] [blame] | 48 | public class PortChainSfMapManager implements PortChainSfMapService { |
| 49 | |
| 50 | private static final String PORT_CHAIN_ID_NULL = "PortChain ID cannot be null"; |
| 51 | |
| 52 | private final Logger log = getLogger(getClass()); |
| 53 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 54 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Phaneendra Manda | 0c42342 | 2016-04-19 00:31:53 +0530 | [diff] [blame] | 55 | protected PortChainService portChainService; |
| 56 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 57 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Phaneendra Manda | 0c42342 | 2016-04-19 00:31:53 +0530 | [diff] [blame] | 58 | protected PortPairGroupService portPairGroupService; |
| 59 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 60 | @Reference(cardinality = ReferenceCardinality.MANDATORY) |
Phaneendra Manda | 0c42342 | 2016-04-19 00:31:53 +0530 | [diff] [blame] | 61 | protected PortPairService portPairService; |
| 62 | |
| 63 | @Activate |
| 64 | public void activate() { |
| 65 | log.info("Started"); |
| 66 | } |
| 67 | |
| 68 | @Deactivate |
| 69 | public void deactivate() { |
| 70 | log.info("Stopped"); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public boolean exists(PortChainId portChainId) { |
| 75 | checkNotNull(portChainId, PORT_CHAIN_ID_NULL); |
| 76 | return portChainService.exists(portChainId); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public List<ServiceFunctionGroup> getServiceFunctions(PortChainId portChainId) { |
| 81 | List<ServiceFunctionGroup> serviceFunctionGroupList = Lists.newArrayList(); |
| 82 | PortChain portChain = portChainService.getPortChain(portChainId); |
| 83 | // Go through the port pair group list |
| 84 | List<PortPairGroupId> portPairGrpList = portChain.portPairGroups(); |
| 85 | ListIterator<PortPairGroupId> listGrpIterator = portPairGrpList.listIterator(); |
| 86 | |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 87 | while (listGrpIterator.hasNext()) { |
Phaneendra Manda | 0c42342 | 2016-04-19 00:31:53 +0530 | [diff] [blame] | 88 | PortPairGroupId portPairGroupId = listGrpIterator.next(); |
| 89 | PortPairGroup portPairGroup = portPairGroupService.getPortPairGroup(portPairGroupId); |
| 90 | ServiceFunctionGroup sfg = new ServiceFunctionGroup(portPairGroup.name(), portPairGroup.description(), |
| 91 | portPairGroup.portPairLoadMap()); |
| 92 | serviceFunctionGroupList.add(sfg); |
| 93 | } |
Phaneendra Manda | 8db7d09 | 2016-06-04 00:17:24 +0530 | [diff] [blame] | 94 | return ImmutableList.copyOf(serviceFunctionGroupList); |
Phaneendra Manda | 0c42342 | 2016-04-19 00:31:53 +0530 | [diff] [blame] | 95 | } |
| 96 | } |