blob: 4df07929f51eb70e2adb0e5a4b8ff0d07459ef43 [file] [log] [blame]
Mahesh Poojary S335e7c32015-10-29 10:16:51 +05301/*
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 */
16package org.onosproject.sfc.manager.impl;
17
18import static org.slf4j.LoggerFactory.getLogger;
19
20import org.apache.felix.scr.annotations.Activate;
21import org.apache.felix.scr.annotations.Component;
22import org.apache.felix.scr.annotations.Deactivate;
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +053023import org.apache.felix.scr.annotations.Reference;
24import org.apache.felix.scr.annotations.ReferenceCardinality;
Mahesh Poojary S335e7c32015-10-29 10:16:51 +053025import org.apache.felix.scr.annotations.Service;
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +053026import org.onlab.util.KryoNamespace;
27import org.onosproject.core.ApplicationId;
28import org.onosproject.core.CoreService;
Mahesh Poojary S335e7c32015-10-29 10:16:51 +053029import org.onosproject.sfc.manager.SfcService;
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +053030import org.onosproject.vtnrsc.PortPair;
31import org.onosproject.vtnrsc.PortPairId;
32import org.onosproject.vtnrsc.PortPairGroup;
33import org.onosproject.vtnrsc.PortPairGroupId;
34import org.onosproject.vtnrsc.FlowClassifier;
35import org.onosproject.vtnrsc.FlowClassifierId;
Mahesh Poojary S335e7c32015-10-29 10:16:51 +053036import org.onosproject.vtnrsc.PortChain;
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +053037import org.onosproject.vtnrsc.PortChainId;
38import org.onosproject.vtnrsc.TenantId;
39import org.onosproject.vtnrsc.event.VtnRscEvent;
40import org.onosproject.vtnrsc.event.VtnRscListener;
41import org.onosproject.vtnrsc.service.VtnRscService;
42
Mahesh Poojary S335e7c32015-10-29 10:16:51 +053043import org.slf4j.Logger;
44
45/**
46 * Provides implementation of SFC Service.
47 */
48@Component(immediate = true)
49@Service
50public class SfcManager implements SfcService {
51
52 private final Logger log = getLogger(getClass());
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +053053 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 S335e7c32015-10-29 10:16:51 +053064
65 @Activate
66 public void activate() {
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +053067 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 S335e7c32015-10-29 10:16:51 +053078 log.info("Started");
79 }
80
81 @Deactivate
82 public void deactivate() {
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +053083 vtnRscService.removeListener(vtnRscListener);
84
Mahesh Poojary S335e7c32015-10-29 10:16:51 +053085 log.info("Stopped");
86 }
87
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +053088 /*
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 S335e7c32015-10-29 10:16:51 +0530139 @Override
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +0530140 public void onPortPairCreated(PortPair portPair) {
Mahesh Poojary S335e7c32015-10-29 10:16:51 +0530141 log.debug("onPortPairCreated");
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +0530142 // TODO: Modify forwarding rule on port-pair creation.
Mahesh Poojary S335e7c32015-10-29 10:16:51 +0530143 }
144
145 @Override
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +0530146 public void onPortPairDeleted(PortPair portPair) {
Mahesh Poojary S335e7c32015-10-29 10:16:51 +0530147 log.debug("onPortPairDeleted");
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +0530148 // TODO: Modify forwarding rule on port-pair deletion.
Mahesh Poojary S335e7c32015-10-29 10:16:51 +0530149 }
150
151 @Override
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +0530152 public void onPortPairGroupCreated(PortPairGroup portPairGroup) {
Mahesh Poojary S335e7c32015-10-29 10:16:51 +0530153 log.debug("onPortPairGroupCreated");
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +0530154 // TODO: Modify forwarding rule on port-pair-group creation.
Mahesh Poojary S335e7c32015-10-29 10:16:51 +0530155 }
156
157 @Override
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +0530158 public void onPortPairGroupDeleted(PortPairGroup portPairGroup) {
Mahesh Poojary S335e7c32015-10-29 10:16:51 +0530159 log.debug("onPortPairGroupDeleted");
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +0530160 // TODO: Modify forwarding rule on port-pair-group deletion.
Mahesh Poojary S335e7c32015-10-29 10:16:51 +0530161 }
162
163 @Override
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +0530164 public void onFlowClassifierCreated(FlowClassifier flowClassifier) {
Mahesh Poojary S335e7c32015-10-29 10:16:51 +0530165 log.debug("onFlowClassifierCreated");
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +0530166 // TODO: Modify forwarding rule on flow-classifier creation.
Mahesh Poojary S335e7c32015-10-29 10:16:51 +0530167 }
168
169 @Override
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +0530170 public void onFlowClassifierDeleted(FlowClassifier flowClassifier) {
Mahesh Poojary S335e7c32015-10-29 10:16:51 +0530171 log.debug("onFlowClassifierDeleted");
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +0530172 // TODO: Modify forwarding rule on flow-classifier deletion.
Mahesh Poojary S335e7c32015-10-29 10:16:51 +0530173 }
174
175 @Override
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +0530176 public void onPortChainCreated(PortChain portChain) {
177 log.debug("onPortChainCreated");
178 //TODO: Apply forwarding rule on port-chain creation.
Mahesh Poojary S335e7c32015-10-29 10:16:51 +0530179 }
180
181 @Override
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +0530182 public void onPortChainDeleted(PortChain portChain) {
Mahesh Poojary S335e7c32015-10-29 10:16:51 +0530183 log.debug("onPortChainDeleted");
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +0530184 //TODO: Apply forwarding rule on port-chain deletion.
Mahesh Poojary S335e7c32015-10-29 10:16:51 +0530185 }
Mahesh Poojary Sc9c10f92015-11-30 17:18:05 +0530186}