Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 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.sfc.manager.impl; |
| 17 | |
| 18 | import static org.slf4j.LoggerFactory.getLogger; |
| 19 | |
| 20 | import org.apache.felix.scr.annotations.Activate; |
| 21 | import org.apache.felix.scr.annotations.Component; |
| 22 | import org.apache.felix.scr.annotations.Deactivate; |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 23 | import org.apache.felix.scr.annotations.Reference; |
| 24 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 25 | import org.apache.felix.scr.annotations.Service; |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 26 | import org.onlab.util.KryoNamespace; |
| 27 | import org.onosproject.core.ApplicationId; |
| 28 | import org.onosproject.core.CoreService; |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 29 | import org.onosproject.sfc.manager.SfcService; |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 30 | import org.onosproject.vtnrsc.PortPair; |
| 31 | import org.onosproject.vtnrsc.PortPairId; |
| 32 | import org.onosproject.vtnrsc.PortPairGroup; |
| 33 | import org.onosproject.vtnrsc.PortPairGroupId; |
| 34 | import org.onosproject.vtnrsc.FlowClassifier; |
| 35 | import org.onosproject.vtnrsc.FlowClassifierId; |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 36 | import org.onosproject.vtnrsc.PortChain; |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 37 | import org.onosproject.vtnrsc.PortChainId; |
| 38 | import org.onosproject.vtnrsc.TenantId; |
| 39 | import org.onosproject.vtnrsc.event.VtnRscEvent; |
| 40 | import org.onosproject.vtnrsc.event.VtnRscListener; |
| 41 | import org.onosproject.vtnrsc.service.VtnRscService; |
| 42 | |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 43 | import org.slf4j.Logger; |
| 44 | |
| 45 | /** |
| 46 | * Provides implementation of SFC Service. |
| 47 | */ |
| 48 | @Component(immediate = true) |
| 49 | @Service |
| 50 | public class SfcManager implements SfcService { |
| 51 | |
| 52 | private final Logger log = getLogger(getClass()); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 53 | private static final String APP_ID = "org.onosproject.app.vtn"; |
| 54 | |
| 55 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 56 | protected VtnRscService vtnRscService; |
| 57 | |
| 58 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 59 | protected CoreService coreService; |
| 60 | |
| 61 | protected ApplicationId appId; |
| 62 | |
| 63 | private final VtnRscListener vtnRscListener = new InnerVtnRscListener(); |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 64 | |
| 65 | @Activate |
| 66 | public void activate() { |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 67 | appId = coreService.registerApplication(APP_ID); |
| 68 | |
| 69 | vtnRscService.addListener(vtnRscListener); |
| 70 | |
| 71 | KryoNamespace.Builder serializer = KryoNamespace.newBuilder() |
| 72 | .register(TenantId.class) |
| 73 | .register(PortPairId.class) |
| 74 | .register(PortPairGroupId.class) |
| 75 | .register(FlowClassifierId.class) |
| 76 | .register(PortChainId.class); |
| 77 | |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 78 | log.info("Started"); |
| 79 | } |
| 80 | |
| 81 | @Deactivate |
| 82 | public void deactivate() { |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 83 | vtnRscService.removeListener(vtnRscListener); |
| 84 | |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 85 | log.info("Stopped"); |
| 86 | } |
| 87 | |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 88 | /* |
| 89 | * Handle events. |
| 90 | */ |
| 91 | private class InnerVtnRscListener implements VtnRscListener { |
| 92 | @Override |
| 93 | public void event(VtnRscEvent event) { |
| 94 | |
| 95 | if (VtnRscEvent.Type.PORT_PAIR_PUT == event.type()) { |
| 96 | PortPair portPair = (PortPair) event.subject(); |
| 97 | onPortPairCreated(portPair); |
| 98 | } else if (VtnRscEvent.Type.PORT_PAIR_DELETE == event.type()) { |
| 99 | PortPair portPair = (PortPair) event.subject(); |
| 100 | onPortPairDeleted(portPair); |
| 101 | } else if (VtnRscEvent.Type.PORT_PAIR_UPDATE == event.type()) { |
| 102 | PortPair portPair = (PortPair) event.subject(); |
| 103 | onPortPairDeleted(portPair); |
| 104 | onPortPairCreated(portPair); |
| 105 | } else if (VtnRscEvent.Type.PORT_PAIR_GROUP_PUT == event.type()) { |
| 106 | PortPairGroup portPairGroup = (PortPairGroup) event.subject(); |
| 107 | onPortPairGroupCreated(portPairGroup); |
| 108 | } else if (VtnRscEvent.Type.PORT_PAIR_GROUP_DELETE == event.type()) { |
| 109 | PortPairGroup portPairGroup = (PortPairGroup) event.subject(); |
| 110 | onPortPairGroupDeleted(portPairGroup); |
| 111 | } else if (VtnRscEvent.Type.PORT_PAIR_GROUP_UPDATE == event.type()) { |
| 112 | PortPairGroup portPairGroup = (PortPairGroup) event.subject(); |
| 113 | onPortPairGroupDeleted(portPairGroup); |
| 114 | onPortPairGroupCreated(portPairGroup); |
| 115 | } else if (VtnRscEvent.Type.FLOW_CLASSIFIER_PUT == event.type()) { |
| 116 | FlowClassifier flowClassifier = (FlowClassifier) event.subject(); |
| 117 | onFlowClassifierCreated(flowClassifier); |
| 118 | } else if (VtnRscEvent.Type.FLOW_CLASSIFIER_DELETE == event.type()) { |
| 119 | FlowClassifier flowClassifier = (FlowClassifier) event.subject(); |
| 120 | onFlowClassifierDeleted(flowClassifier); |
| 121 | } else if (VtnRscEvent.Type.FLOW_CLASSIFIER_UPDATE == event.type()) { |
| 122 | FlowClassifier flowClassifier = (FlowClassifier) event.subject(); |
| 123 | onFlowClassifierDeleted(flowClassifier); |
| 124 | onFlowClassifierCreated(flowClassifier); |
| 125 | } else if (VtnRscEvent.Type.PORT_CHAIN_PUT == event.type()) { |
| 126 | PortChain portChain = (PortChain) event.subject(); |
| 127 | onPortChainCreated(portChain); |
| 128 | } else if (VtnRscEvent.Type.PORT_CHAIN_DELETE == event.type()) { |
| 129 | PortChain portChain = (PortChain) event.subject(); |
| 130 | onPortChainDeleted(portChain); |
| 131 | } else if (VtnRscEvent.Type.PORT_CHAIN_UPDATE == event.type()) { |
| 132 | PortChain portChain = (PortChain) event.subject(); |
| 133 | onPortChainDeleted(portChain); |
| 134 | onPortChainCreated(portChain); |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 139 | @Override |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 140 | public void onPortPairCreated(PortPair portPair) { |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 141 | log.debug("onPortPairCreated"); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 142 | // TODO: Modify forwarding rule on port-pair creation. |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | @Override |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 146 | public void onPortPairDeleted(PortPair portPair) { |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 147 | log.debug("onPortPairDeleted"); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 148 | // TODO: Modify forwarding rule on port-pair deletion. |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | @Override |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 152 | public void onPortPairGroupCreated(PortPairGroup portPairGroup) { |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 153 | log.debug("onPortPairGroupCreated"); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 154 | // TODO: Modify forwarding rule on port-pair-group creation. |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | @Override |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 158 | public void onPortPairGroupDeleted(PortPairGroup portPairGroup) { |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 159 | log.debug("onPortPairGroupDeleted"); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 160 | // TODO: Modify forwarding rule on port-pair-group deletion. |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | @Override |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 164 | public void onFlowClassifierCreated(FlowClassifier flowClassifier) { |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 165 | log.debug("onFlowClassifierCreated"); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 166 | // TODO: Modify forwarding rule on flow-classifier creation. |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | @Override |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 170 | public void onFlowClassifierDeleted(FlowClassifier flowClassifier) { |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 171 | log.debug("onFlowClassifierDeleted"); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 172 | // TODO: Modify forwarding rule on flow-classifier deletion. |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | @Override |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 176 | public void onPortChainCreated(PortChain portChain) { |
| 177 | log.debug("onPortChainCreated"); |
| 178 | //TODO: Apply forwarding rule on port-chain creation. |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | @Override |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 182 | public void onPortChainDeleted(PortChain portChain) { |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 183 | log.debug("onPortChainDeleted"); |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 184 | //TODO: Apply forwarding rule on port-chain deletion. |
Mahesh Poojary S | 335e7c3 | 2015-10-29 10:16:51 +0530 | [diff] [blame] | 185 | } |
Mahesh Poojary S | c9c10f9 | 2015-11-30 17:18:05 +0530 | [diff] [blame^] | 186 | } |