blob: 3afbec47c763b3440cc385abff99a95ce0078aac [file] [log] [blame]
Priyanka B9bee0802016-04-27 22:06:02 +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.provider.bgpcep.flow.impl;
17
18import org.apache.felix.scr.annotations.Activate;
19import org.apache.felix.scr.annotations.Component;
20import org.apache.felix.scr.annotations.Deactivate;
21import org.apache.felix.scr.annotations.Reference;
22import org.apache.felix.scr.annotations.ReferenceCardinality;
23import org.onosproject.bgp.controller.BgpController;
24import org.onosproject.cfg.ComponentConfigService;
25import org.onosproject.core.ApplicationId;
26import org.onosproject.net.flow.FlowRule;
27import org.onosproject.net.flow.FlowRuleBatchOperation;
28import org.onosproject.net.flow.FlowRuleProvider;
29import org.onosproject.net.flow.FlowRuleProviderRegistry;
30import org.onosproject.net.flow.FlowRuleProviderService;
31import org.onosproject.net.flow.criteria.Criterion;
32import org.onosproject.net.provider.AbstractProvider;
33import org.onosproject.net.provider.ProviderId;
34import org.onosproject.net.resource.ResourceService;
35import org.onosproject.pcep.controller.PcepClient;
36import org.onosproject.pcep.controller.PcepClientController;
37import org.osgi.service.component.ComponentContext;
38import org.slf4j.Logger;
39
40import static org.slf4j.LoggerFactory.getLogger;
41
42/**
43 * Implementation of BGP-PCEP flow provider.
44 */
45@Component(immediate = true)
46public class BgpcepFlowRuleProvider extends AbstractProvider
47 implements FlowRuleProvider {
48
49 private final Logger log = getLogger(getClass());
50
51 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
52 protected FlowRuleProviderRegistry providerRegistry;
53
54 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
55 protected ComponentConfigService cfgService;
56
57 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
58 protected BgpController bgpController;
59
60 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
61 protected PcepClientController pcepController;
62
63 @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
64 protected ResourceService resourceService;
65
66 private FlowRuleProviderService providerService;
67
68 /**
69 * Creates a BgpFlow host provider.
70 */
71 public BgpcepFlowRuleProvider() {
72 super(new ProviderId("l3", "org.onosproject.provider.bgpcep"));
73 }
74
75 @Activate
76 public void activate(ComponentContext context) {
77 cfgService.registerProperties(getClass());
78 providerService = providerRegistry.register(this);
79 log.info("Started");
80 }
81
82 @Deactivate
83 public void deactivate(ComponentContext context) {
84 cfgService.unregisterProperties(getClass(), false);
85 providerRegistry.unregister(this);
86 providerService = null;
87 log.info("Stopped");
88 }
89
90 @Override
91 public void applyFlowRule(FlowRule... flowRules) {
92 for (FlowRule flowRule : flowRules) {
93 applyRule(flowRule);
94 }
95 }
96
97 private void applyRule(FlowRule flowRule) {
98 flowRule.selector().criteria()
99 .forEach(c -> {
100 // If Criterion type is MPLS_LABEL, push labels through PCEP client
101 if (c.type() == Criterion.Type.MPLS_LABEL) {
102 PcepClient pcc;
103 /** PCC client session is based on LSR ID, get the LSR ID for a specific device to
104 push the flows */
105
106 //TODO: commented code has dependency with other patch
107 /* Set<TeRouterId> lrsIds = resourceService.getAvailableResourceValues(Resources
108 .discrete(flowRule.deviceId()).id(), TeRouterId.class);
109
110 lrsIds.forEach(lsrId ->
111 {
112 if (pcepController.getClient(PccId.pccId(lsrId)) != null) {
113 pcc = pcepController.getClient(PccId.pccId(lsrId));
114 }
115 });*/
116 // TODO: Build message and send the PCEP label message via PCEP client
117 } else {
118 // TODO: Get the BGP peer based on deviceId and send the message
119 }
120 });
121 }
122
123 @Override
124 public void removeFlowRule(FlowRule... flowRules) {
125 for (FlowRule flowRule : flowRules) {
126 removeRule(flowRule);
127 }
128 }
129
130 private void removeRule(FlowRule flowRule) {
131 flowRule.selector().criteria()
132 .forEach(c -> {
133 // If Criterion type is MPLS_LABEL, remove the specified flow rules
134 if (c.type() == Criterion.Type.MPLS_LABEL) {
135 PcepClient pcc;
136 /** PCC client session is based on LSR ID, get the LSR ID for a specific device to
137 push the flows */
138
139 //TODO: commented code has dependency with other patch
140 /* Set<TeRouterId> lrsIds = resourceService.getAvailableResourceValues(Resources
141 .discrete(flowRule.deviceId()).id(), TeRouterId.class);
142
143 lrsIds.forEach(lsrId ->
144 {
145 if (pcepController.getClient(PccId.pccId(lsrId)) != null) {
146 pcc = pcepController.getClient(PccId.pccId(lsrId));
147 }
148 });*/
149 // TODO: Build message and send the PCEP label message via PCEP client
150 } else {
151 // TODO: Get the BGP peer based on deviceId and send the message
152 }
153 });
154 }
155
156 @Override
157 public void removeRulesById(ApplicationId id, FlowRule... flowRules) {
158 // TODO
159 removeFlowRule(flowRules);
160 }
161
162 @Override
163 public void executeBatch(FlowRuleBatchOperation batch) {
164 //TODO
165 }
166}