blob: d5932622c7b4bff4d215d55710fc5e868fab069d [file] [log] [blame]
Jonghwan Hyuned478dc2018-08-06 15:35:18 +09001/*
2 * Copyright 2017-present Open Networking Foundation
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.pipelines.fabric;
17
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090018import com.google.common.collect.Sets;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090019import org.onosproject.core.ApplicationId;
20import org.onosproject.core.CoreService;
21import org.onosproject.inbandtelemetry.api.IntConfig;
22import org.onosproject.inbandtelemetry.api.IntIntent;
23import org.onosproject.inbandtelemetry.api.IntObjective;
24import org.onosproject.inbandtelemetry.api.IntProgrammable;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090025import org.onosproject.net.DeviceId;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090026import org.onosproject.net.PortNumber;
Carmelo Casconefa421582018-09-13 10:05:57 -070027import org.onosproject.net.config.NetworkConfigService;
Carmelo Cascone3977ea42019-02-28 13:43:42 -080028import org.onosproject.net.device.DeviceService;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090029import org.onosproject.net.flow.DefaultFlowRule;
30import org.onosproject.net.flow.DefaultTrafficSelector;
31import org.onosproject.net.flow.DefaultTrafficTreatment;
32import org.onosproject.net.flow.FlowRule;
33import org.onosproject.net.flow.FlowRuleService;
Carmelo Casconefa421582018-09-13 10:05:57 -070034import org.onosproject.net.flow.TableId;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090035import org.onosproject.net.flow.TrafficSelector;
36import org.onosproject.net.flow.TrafficTreatment;
37import org.onosproject.net.flow.criteria.Criterion;
38import org.onosproject.net.flow.criteria.IPCriterion;
39import org.onosproject.net.flow.criteria.PiCriterion;
40import org.onosproject.net.flow.criteria.TcpPortCriterion;
41import org.onosproject.net.flow.criteria.UdpPortCriterion;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090042import org.onosproject.net.pi.model.PiTableId;
43import org.onosproject.net.pi.runtime.PiAction;
44import org.onosproject.net.pi.runtime.PiActionParam;
Carmelo Cascone3977ea42019-02-28 13:43:42 -080045import org.osgi.service.component.annotations.Reference;
46import org.osgi.service.component.annotations.ReferenceCardinality;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090047
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090048import java.util.Set;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090049import java.util.stream.Collectors;
Carmelo Casconefa421582018-09-13 10:05:57 -070050import java.util.stream.StreamSupport;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090051
Carmelo Casconefa421582018-09-13 10:05:57 -070052import static org.onlab.util.ImmutableByteSequence.copyFrom;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090053
Carmelo Casconefa421582018-09-13 10:05:57 -070054/**
55 * Implementation of INT programmable behavior for fabric.p4. Currently supports
56 * only SOURCE and TRANSIT functionalities.
57 */
Carmelo Casconeb5324e72018-11-25 02:26:32 -080058public class FabricIntProgrammable extends AbstractFabricHandlerBehavior
59 implements IntProgrammable {
Carmelo Casconefa421582018-09-13 10:05:57 -070060
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090061 // TODO: change this value to the value of diameter of a network.
Carmelo Casconefa421582018-09-13 10:05:57 -070062 private static final int DEFAULT_PRIORITY = 10000;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090063 private static final int MAXHOP = 64;
64 private static final int PORTMASK = 0xffff;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090065 private static final int PKT_INSTANCE_TYPE_INGRESS_CLONE = 1;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090066
67 private static final Set<Criterion.Type> SUPPORTED_CRITERION = Sets.newHashSet(
68 Criterion.Type.IPV4_DST, Criterion.Type.IPV4_SRC,
69 Criterion.Type.UDP_SRC, Criterion.Type.UDP_DST,
70 Criterion.Type.TCP_SRC, Criterion.Type.TCP_DST,
71 Criterion.Type.IP_PROTO);
72
Carmelo Casconefa421582018-09-13 10:05:57 -070073 private static final Set<PiTableId> TABLES_TO_CLEANUP = Sets.newHashSet(
74 FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_TB_INT_INSERT,
75 FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SOURCE,
76 FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SINK,
77 FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_SOURCE_TB_INT_SOURCE,
78 FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_REPORT_TB_GENERATE_REPORT
79 );
80
Ray Milkeyd84f89b2018-08-17 14:54:17 -070081 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090082 private FlowRuleService flowRuleService;
83
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090084 private CoreService coreService;
Carmelo Casconefa421582018-09-13 10:05:57 -070085 private NetworkConfigService cfgService;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090086 private DeviceId deviceId;
Carmelo Casconefa421582018-09-13 10:05:57 -070087 private ApplicationId appId;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090088
Carmelo Casconefa421582018-09-13 10:05:57 -070089 private boolean setupBehaviour() {
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090090 deviceId = this.data().deviceId();
91 flowRuleService = handler().get(FlowRuleService.class);
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090092 coreService = handler().get(CoreService.class);
Carmelo Casconefa421582018-09-13 10:05:57 -070093 cfgService = handler().get(NetworkConfigService.class);
94 appId = coreService.getAppId(PipeconfLoader.PIPELINE_APP_NAME);
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090095 if (appId == null) {
Carmelo Casconefa421582018-09-13 10:05:57 -070096 log.warn("Application ID is null. Cannot initialize behaviour.");
97 return false;
98 }
99 return true;
100 }
101
102 @Override
103 public boolean init() {
104
105 if (!setupBehaviour()) {
106 return false;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900107 }
108
Carmelo Cascone3977ea42019-02-28 13:43:42 -0800109 // FIXME: create config class for INT to allow specifying arbitrary
110 // switch IDs. The one for the GeneralDeviceProvider was temporary and
111 // now has been removed. For now we use the chassis ID.
112 // final GeneralProviderDeviceConfig cfg = cfgService.getConfig(
113 // deviceId, GeneralProviderDeviceConfig.class);
114 // if (cfg == null) {
115 // log.warn("Missing GeneralProviderDevice config for {}", deviceId);
116 // return false;
117 // }
118 // final String switchId = cfg.protocolsInfo().containsKey("int") ?
119 // cfg.protocolsInfo().get("int").configValues().get("switchId")
120 // : null;
121 // if (switchId == null || switchId.isEmpty()) {
122 // log.warn("Missing INT device config for {}", deviceId);
123 // return false;
124 // }
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900125
Carmelo Cascone3977ea42019-02-28 13:43:42 -0800126 PiActionParam transitIdParam = new PiActionParam(
127 FabricConstants.SWITCH_ID,
128 copyFrom(handler().get(DeviceService.class)
129 .getDevice(deviceId).chassisId().id()));
Carmelo Casconefa421582018-09-13 10:05:57 -0700130
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900131 PiAction transitAction = PiAction.builder()
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700132 .withId(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INIT_METADATA)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900133 .withParameter(transitIdParam)
134 .build();
135 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
136 .piTableAction(transitAction)
137 .build();
Carmelo Casconefa421582018-09-13 10:05:57 -0700138 TrafficSelector selector = DefaultTrafficSelector.builder()
139 .matchPi(PiCriterion.builder().matchExact(
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800140 FabricConstants.HDR_INT_IS_VALID, (byte) 0x01)
Carmelo Casconefa421582018-09-13 10:05:57 -0700141 .build())
142 .build();
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900143
144 FlowRule transitFlowRule = DefaultFlowRule.builder()
Carmelo Casconefa421582018-09-13 10:05:57 -0700145 .withSelector(selector)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900146 .withTreatment(treatment)
147 .fromApp(appId)
148 .withPriority(DEFAULT_PRIORITY)
149 .makePermanent()
150 .forDevice(deviceId)
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700151 .forTable(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_TB_INT_INSERT)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900152 .build();
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900153
Carmelo Casconefa421582018-09-13 10:05:57 -0700154 flowRuleService.applyFlowRules(transitFlowRule);
155 return true;
156 }
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900157
Carmelo Casconefa421582018-09-13 10:05:57 -0700158 @Override
159 public boolean setSourcePort(PortNumber port) {
160
161 if (!setupBehaviour()) {
162 return false;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900163 }
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900164
Carmelo Casconefa421582018-09-13 10:05:57 -0700165 PiCriterion ingressCriterion = PiCriterion.builder()
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800166 .matchExact(FabricConstants.HDR_IG_PORT, port.toLong())
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900167 .build();
Carmelo Casconefa421582018-09-13 10:05:57 -0700168 TrafficSelector srcSelector = DefaultTrafficSelector.builder()
169 .matchPi(ingressCriterion)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900170 .build();
Carmelo Casconefa421582018-09-13 10:05:57 -0700171 PiAction setSourceAct = PiAction.builder()
172 .withId(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_INT_SET_SOURCE)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900173 .build();
Carmelo Casconefa421582018-09-13 10:05:57 -0700174 TrafficTreatment srcTreatment = DefaultTrafficTreatment.builder()
175 .piTableAction(setSourceAct)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900176 .build();
Carmelo Casconefa421582018-09-13 10:05:57 -0700177 FlowRule srcFlowRule = DefaultFlowRule.builder()
178 .withSelector(srcSelector)
179 .withTreatment(srcTreatment)
180 .fromApp(appId)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900181 .withPriority(DEFAULT_PRIORITY)
182 .makePermanent()
183 .forDevice(deviceId)
Carmelo Casconefa421582018-09-13 10:05:57 -0700184 .forTable(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SOURCE)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900185 .build();
Carmelo Casconefa421582018-09-13 10:05:57 -0700186 flowRuleService.applyFlowRules(srcFlowRule);
187 return true;
188 }
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900189
Carmelo Casconefa421582018-09-13 10:05:57 -0700190 @Override
191 public boolean setSinkPort(PortNumber port) {
192
193 if (!setupBehaviour()) {
194 return false;
195 }
196
197 PiCriterion egressCriterion = PiCriterion.builder()
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800198 .matchExact(FabricConstants.HDR_EG_PORT, port.toLong())
Carmelo Casconefa421582018-09-13 10:05:57 -0700199 .build();
200 TrafficSelector sinkSelector = DefaultTrafficSelector.builder()
201 .matchPi(egressCriterion)
202 .build();
203 PiAction setSinkAct = PiAction.builder()
204 .withId(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_INT_SET_SINK)
205 .build();
206 TrafficTreatment sinkTreatment = DefaultTrafficTreatment.builder()
207 .piTableAction(setSinkAct)
208 .build();
209 FlowRule sinkFlowRule = DefaultFlowRule.builder()
210 .withSelector(sinkSelector)
211 .withTreatment(sinkTreatment)
212 .fromApp(appId)
213 .withPriority(DEFAULT_PRIORITY)
214 .makePermanent()
215 .forDevice(deviceId)
216 .forTable(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SINK)
217 .build();
218 flowRuleService.applyFlowRules(sinkFlowRule);
219 return true;
220 }
221
222 @Override
223 public boolean addIntObjective(IntObjective obj) {
224
225 if (!setupBehaviour()) {
226 return false;
227 }
228
229 return processIntObjective(obj, true);
230 }
231
232 @Override
233 public boolean removeIntObjective(IntObjective obj) {
234
235 if (!setupBehaviour()) {
236 return false;
237 }
238
239 return processIntObjective(obj, false);
240 }
241
242 @Override
243 public boolean setupIntConfig(IntConfig config) {
244
245 if (!setupBehaviour()) {
246 return false;
247 }
248
249 return setupIntReportInternal(config);
250 }
251
252 @Override
253 public void cleanup() {
254
255 if (!setupBehaviour()) {
256 return;
257 }
258
259 StreamSupport.stream(flowRuleService.getFlowEntries(
260 data().deviceId()).spliterator(), false)
261 .filter(f -> f.table().type() == TableId.Type.PIPELINE_INDEPENDENT)
262 .filter(f -> TABLES_TO_CLEANUP.contains((PiTableId) f.table()))
263 .forEach(flowRuleService::removeFlowRules);
264 }
265
266 @Override
267 public boolean supportsFunctionality(IntFunctionality functionality) {
268 // Sink not fully supported yet.
269 return functionality == IntFunctionality.SOURCE || functionality == IntFunctionality.TRANSIT;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900270 }
271
272 private FlowRule buildWatchlistEntry(IntObjective obj) {
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900273 int instructionBitmap = buildInstructionBitmap(obj.metadataTypes());
274 PiActionParam maxHopParam = new PiActionParam(
275 FabricConstants.MAX_HOP,
Carmelo Casconefa421582018-09-13 10:05:57 -0700276 copyFrom(MAXHOP));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900277 PiActionParam instCntParam = new PiActionParam(
278 FabricConstants.INS_CNT,
Carmelo Casconefa421582018-09-13 10:05:57 -0700279 copyFrom(Integer.bitCount(instructionBitmap)));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900280 PiActionParam inst0003Param = new PiActionParam(
281 FabricConstants.INS_MASK0003,
Carmelo Casconefa421582018-09-13 10:05:57 -0700282 copyFrom((instructionBitmap >> 12) & 0xF));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900283 PiActionParam inst0407Param = new PiActionParam(
284 FabricConstants.INS_MASK0407,
Carmelo Casconefa421582018-09-13 10:05:57 -0700285 copyFrom((instructionBitmap >> 8) & 0xF));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900286
287 PiAction intSourceAction = PiAction.builder()
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700288 .withId(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_SOURCE_INT_SOURCE_DSCP)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900289 .withParameter(maxHopParam)
290 .withParameter(instCntParam)
291 .withParameter(inst0003Param)
292 .withParameter(inst0407Param)
293 .build();
294
295 TrafficTreatment instTreatment = DefaultTrafficTreatment.builder()
296 .piTableAction(intSourceAction)
297 .build();
298
299 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
300 for (Criterion criterion : obj.selector().criteria()) {
301 switch (criterion.type()) {
302 case IPV4_SRC:
303 sBuilder.matchIPSrc(((IPCriterion) criterion).ip());
304 break;
305 case IPV4_DST:
306 sBuilder.matchIPDst(((IPCriterion) criterion).ip());
307 break;
308 case TCP_SRC:
309 sBuilder.matchPi(
310 PiCriterion.builder().matchTernary(
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800311 FabricConstants.HDR_L4_SPORT,
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900312 ((TcpPortCriterion) criterion).tcpPort().toInt(), PORTMASK)
313 .build());
314 break;
315 case UDP_SRC:
316 sBuilder.matchPi(
317 PiCriterion.builder().matchTernary(
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800318 FabricConstants.HDR_L4_SPORT,
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900319 ((UdpPortCriterion) criterion).udpPort().toInt(), PORTMASK)
320 .build());
321 break;
322 case TCP_DST:
323 sBuilder.matchPi(
324 PiCriterion.builder().matchTernary(
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800325 FabricConstants.HDR_L4_DPORT,
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900326 ((TcpPortCriterion) criterion).tcpPort().toInt(), PORTMASK)
327 .build());
328 break;
329 case UDP_DST:
330 sBuilder.matchPi(
331 PiCriterion.builder().matchTernary(
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800332 FabricConstants.HDR_L4_DPORT,
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900333 ((UdpPortCriterion) criterion).udpPort().toInt(), PORTMASK)
334 .build());
335 break;
336 default:
337 log.warn("Unsupported criterion type: {}", criterion.type());
338 }
339 }
340
341 return DefaultFlowRule.builder()
Carmelo Casconefa421582018-09-13 10:05:57 -0700342 .forDevice(deviceId)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900343 .withSelector(sBuilder.build())
344 .withTreatment(instTreatment)
345 .withPriority(DEFAULT_PRIORITY)
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700346 .forTable(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_SOURCE_TB_INT_SOURCE)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900347 .fromApp(appId)
Carmelo Casconefa421582018-09-13 10:05:57 -0700348 .makePermanent()
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900349 .build();
350 }
351
352 private int buildInstructionBitmap(Set<IntIntent.IntMetadataType> metadataTypes) {
353 int instBitmap = 0;
354 for (IntIntent.IntMetadataType metadataType : metadataTypes) {
355 switch (metadataType) {
356 case SWITCH_ID:
357 instBitmap |= (1 << 15);
358 break;
359 case L1_PORT_ID:
360 instBitmap |= (1 << 14);
361 break;
362 case HOP_LATENCY:
363 instBitmap |= (1 << 13);
364 break;
365 case QUEUE_OCCUPANCY:
366 instBitmap |= (1 << 12);
367 break;
368 case INGRESS_TIMESTAMP:
369 instBitmap |= (1 << 11);
370 break;
371 case EGRESS_TIMESTAMP:
372 instBitmap |= (1 << 10);
373 break;
374 case L2_PORT_ID:
375 instBitmap |= (1 << 9);
376 break;
377 case EGRESS_TX_UTIL:
378 instBitmap |= (1 << 8);
379 break;
380 default:
381 log.info("Unsupported metadata type {}. Ignoring...", metadataType);
382 break;
383 }
384 }
385 return instBitmap;
386 }
387
388 /**
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700389 * Returns a subset of Criterion from given selector, which is unsupported
390 * by this INT pipeline.
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900391 *
392 * @param selector a traffic selector
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700393 * @return a subset of Criterion from given selector, unsupported by this
394 * INT pipeline, empty if all criteria are supported.
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900395 */
396 private Set<Criterion> unsupportedSelectors(TrafficSelector selector) {
397 return selector.criteria().stream()
398 .filter(criterion -> !SUPPORTED_CRITERION.contains(criterion.type()))
399 .collect(Collectors.toSet());
400 }
401
402 private boolean processIntObjective(IntObjective obj, boolean install) {
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900403 if (install && !unsupportedSelectors(obj.selector()).isEmpty()) {
Carmelo Casconefa421582018-09-13 10:05:57 -0700404 log.warn("Criteria {} not supported by {} for INT watchlist",
405 unsupportedSelectors(obj.selector()), deviceId);
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900406 return false;
407 }
408
409 FlowRule flowRule = buildWatchlistEntry(obj);
410 if (flowRule != null) {
411 if (install) {
412 flowRuleService.applyFlowRules(flowRule);
413 } else {
414 flowRuleService.removeFlowRules(flowRule);
415 }
416 log.debug("IntObjective {} has been {} {}",
417 obj, install ? "installed to" : "removed from", deviceId);
418 return true;
419 } else {
420 log.warn("Failed to {} IntObjective {} on {}",
421 install ? "install" : "remove", obj, deviceId);
422 return false;
423 }
424 }
425
426 private boolean setupIntReportInternal(IntConfig cfg) {
Carmelo Casconefa421582018-09-13 10:05:57 -0700427 // Report not fully supported yet.
428 return true;
429 // FlowRule reportRule = buildReportEntry(cfg, PKT_INSTANCE_TYPE_INGRESS_CLONE);
430 // if (reportRule != null) {
431 // flowRuleService.applyFlowRules(reportRule);
432 // log.info("Report entry {} has been added to {}", reportRule, this.data().deviceId());
433 // return true;
434 // } else {
435 // log.warn("Failed to add report entry on {}", this.data().deviceId());
436 // return false;
437 // }
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900438 }
439
440 private FlowRule buildReportEntry(IntConfig cfg, int type) {
Carmelo Casconefa421582018-09-13 10:05:57 -0700441
442 if (!setupBehaviour()) {
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900443 return null;
444 }
445
446 PiActionParam srcMacParam = new PiActionParam(
447 FabricConstants.SRC_MAC,
Carmelo Casconefa421582018-09-13 10:05:57 -0700448 copyFrom(cfg.sinkMac().toBytes()));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900449 PiActionParam nextHopMacParam = new PiActionParam(
450 FabricConstants.MON_MAC,
Carmelo Casconefa421582018-09-13 10:05:57 -0700451 copyFrom(cfg.collectorNextHopMac().toBytes()));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900452 PiActionParam srcIpParam = new PiActionParam(
453 FabricConstants.SRC_IP,
Carmelo Casconefa421582018-09-13 10:05:57 -0700454 copyFrom(cfg.sinkIp().toOctets()));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900455 PiActionParam monIpParam = new PiActionParam(
456 FabricConstants.MON_IP,
Carmelo Casconefa421582018-09-13 10:05:57 -0700457 copyFrom(cfg.collectorIp().toOctets()));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900458 PiActionParam monPortParam = new PiActionParam(
459 FabricConstants.MON_PORT,
Carmelo Casconefa421582018-09-13 10:05:57 -0700460 copyFrom(cfg.collectorPort().toInt()));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900461 PiAction reportAction = PiAction.builder()
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700462 .withId(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_REPORT_DO_REPORT_ENCAPSULATION)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900463 .withParameter(srcMacParam)
464 .withParameter(nextHopMacParam)
465 .withParameter(srcIpParam)
466 .withParameter(monIpParam)
467 .withParameter(monPortParam)
468 .build();
469 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
470 .piTableAction(reportAction)
471 .build();
472
473 return DefaultFlowRule.builder()
474 .withTreatment(treatment)
475 .fromApp(appId)
476 .withPriority(DEFAULT_PRIORITY)
477 .makePermanent()
478 .forDevice(this.data().deviceId())
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700479 .forTable(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_REPORT_TB_GENERATE_REPORT)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900480 .build();
481 }
482
483}