blob: a2bf56996429bdc42f9ecf46bf0eff5e80499bb5 [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;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070019import org.osgi.service.component.annotations.Reference;
20import org.osgi.service.component.annotations.ReferenceCardinality;
Ray Milkeydb57f1c2018-10-09 10:39:29 -070021
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090022import org.onosproject.core.ApplicationId;
23import org.onosproject.core.CoreService;
24import org.onosproject.inbandtelemetry.api.IntConfig;
25import org.onosproject.inbandtelemetry.api.IntIntent;
26import org.onosproject.inbandtelemetry.api.IntObjective;
27import org.onosproject.inbandtelemetry.api.IntProgrammable;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090028import org.onosproject.net.DeviceId;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090029import org.onosproject.net.PortNumber;
Carmelo Casconefa421582018-09-13 10:05:57 -070030import org.onosproject.net.config.NetworkConfigService;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090031import org.onosproject.net.flow.DefaultFlowRule;
32import org.onosproject.net.flow.DefaultTrafficSelector;
33import org.onosproject.net.flow.DefaultTrafficTreatment;
34import org.onosproject.net.flow.FlowRule;
35import org.onosproject.net.flow.FlowRuleService;
Carmelo Casconefa421582018-09-13 10:05:57 -070036import org.onosproject.net.flow.TableId;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090037import org.onosproject.net.flow.TrafficSelector;
38import org.onosproject.net.flow.TrafficTreatment;
39import org.onosproject.net.flow.criteria.Criterion;
40import org.onosproject.net.flow.criteria.IPCriterion;
41import org.onosproject.net.flow.criteria.PiCriterion;
42import org.onosproject.net.flow.criteria.TcpPortCriterion;
43import org.onosproject.net.flow.criteria.UdpPortCriterion;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090044import org.onosproject.net.pi.model.PiTableId;
45import org.onosproject.net.pi.runtime.PiAction;
46import org.onosproject.net.pi.runtime.PiActionParam;
Carmelo Casconefa421582018-09-13 10:05:57 -070047import org.onosproject.provider.general.device.api.GeneralProviderDeviceConfig;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090048
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090049import java.util.Set;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090050import java.util.stream.Collectors;
Carmelo Casconefa421582018-09-13 10:05:57 -070051import java.util.stream.StreamSupport;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090052
Carmelo Casconefa421582018-09-13 10:05:57 -070053import static org.onlab.util.ImmutableByteSequence.copyFrom;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090054
Carmelo Casconefa421582018-09-13 10:05:57 -070055/**
56 * Implementation of INT programmable behavior for fabric.p4. Currently supports
57 * only SOURCE and TRANSIT functionalities.
58 */
Carmelo Casconeb5324e72018-11-25 02:26:32 -080059public class FabricIntProgrammable extends AbstractFabricHandlerBehavior
60 implements IntProgrammable {
Carmelo Casconefa421582018-09-13 10:05:57 -070061
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090062 // TODO: change this value to the value of diameter of a network.
Carmelo Casconefa421582018-09-13 10:05:57 -070063 private static final int DEFAULT_PRIORITY = 10000;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090064 private static final int MAXHOP = 64;
65 private static final int PORTMASK = 0xffff;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090066 private static final int PKT_INSTANCE_TYPE_INGRESS_CLONE = 1;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090067
68 private static final Set<Criterion.Type> SUPPORTED_CRITERION = Sets.newHashSet(
69 Criterion.Type.IPV4_DST, Criterion.Type.IPV4_SRC,
70 Criterion.Type.UDP_SRC, Criterion.Type.UDP_DST,
71 Criterion.Type.TCP_SRC, Criterion.Type.TCP_DST,
72 Criterion.Type.IP_PROTO);
73
Carmelo Casconefa421582018-09-13 10:05:57 -070074 private static final Set<PiTableId> TABLES_TO_CLEANUP = Sets.newHashSet(
75 FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_TB_INT_INSERT,
76 FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SOURCE,
77 FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SINK,
78 FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_SOURCE_TB_INT_SOURCE,
79 FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_REPORT_TB_GENERATE_REPORT
80 );
81
Ray Milkeyd84f89b2018-08-17 14:54:17 -070082 @Reference(cardinality = ReferenceCardinality.MANDATORY)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090083 private FlowRuleService flowRuleService;
84
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090085 private CoreService coreService;
Carmelo Casconefa421582018-09-13 10:05:57 -070086 private NetworkConfigService cfgService;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090087 private DeviceId deviceId;
Carmelo Casconefa421582018-09-13 10:05:57 -070088 private ApplicationId appId;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090089
Carmelo Casconefa421582018-09-13 10:05:57 -070090 private boolean setupBehaviour() {
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090091 deviceId = this.data().deviceId();
92 flowRuleService = handler().get(FlowRuleService.class);
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090093 coreService = handler().get(CoreService.class);
Carmelo Casconefa421582018-09-13 10:05:57 -070094 cfgService = handler().get(NetworkConfigService.class);
95 appId = coreService.getAppId(PipeconfLoader.PIPELINE_APP_NAME);
Jonghwan Hyuned478dc2018-08-06 15:35:18 +090096 if (appId == null) {
Carmelo Casconefa421582018-09-13 10:05:57 -070097 log.warn("Application ID is null. Cannot initialize behaviour.");
98 return false;
99 }
100 return true;
101 }
102
103 @Override
104 public boolean init() {
105
106 if (!setupBehaviour()) {
107 return false;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900108 }
109
Carmelo Casconefa421582018-09-13 10:05:57 -0700110 final GeneralProviderDeviceConfig cfg = cfgService.getConfig(
111 deviceId, GeneralProviderDeviceConfig.class);
112 if (cfg == null) {
113 log.warn("Missing GeneralProviderDevice config for {}", deviceId);
114 return false;
115 }
116 final String switchId = cfg.protocolsInfo().containsKey("int") ?
117 cfg.protocolsInfo().get("int").configValues().get("switchId")
118 : null;
119 if (switchId == null || switchId.isEmpty()) {
120 log.warn("Missing INT device config for {}", deviceId);
121 return false;
122 }
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900123
Carmelo Casconefa421582018-09-13 10:05:57 -0700124 PiActionParam transitIdParam;
125 try {
126 transitIdParam = new PiActionParam(
127 FabricConstants.SWITCH_ID,
128 // FIXME set switch ID from netcfg
129 copyFrom(Integer.parseInt(switchId)));
130 } catch (NumberFormatException e) {
131 log.warn("Invalid INT switch ID for {}: {}", deviceId, switchId);
132 return false;
133 }
134
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900135 PiAction transitAction = PiAction.builder()
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700136 .withId(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_INIT_METADATA)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900137 .withParameter(transitIdParam)
138 .build();
139 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
140 .piTableAction(transitAction)
141 .build();
Carmelo Casconefa421582018-09-13 10:05:57 -0700142 TrafficSelector selector = DefaultTrafficSelector.builder()
143 .matchPi(PiCriterion.builder().matchExact(
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800144 FabricConstants.HDR_INT_IS_VALID, (byte) 0x01)
Carmelo Casconefa421582018-09-13 10:05:57 -0700145 .build())
146 .build();
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900147
148 FlowRule transitFlowRule = DefaultFlowRule.builder()
Carmelo Casconefa421582018-09-13 10:05:57 -0700149 .withSelector(selector)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900150 .withTreatment(treatment)
151 .fromApp(appId)
152 .withPriority(DEFAULT_PRIORITY)
153 .makePermanent()
154 .forDevice(deviceId)
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700155 .forTable(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_TRANSIT_TB_INT_INSERT)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900156 .build();
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900157
Carmelo Casconefa421582018-09-13 10:05:57 -0700158 flowRuleService.applyFlowRules(transitFlowRule);
159 return true;
160 }
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900161
Carmelo Casconefa421582018-09-13 10:05:57 -0700162 @Override
163 public boolean setSourcePort(PortNumber port) {
164
165 if (!setupBehaviour()) {
166 return false;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900167 }
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900168
Carmelo Casconefa421582018-09-13 10:05:57 -0700169 PiCriterion ingressCriterion = PiCriterion.builder()
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800170 .matchExact(FabricConstants.HDR_IG_PORT, port.toLong())
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900171 .build();
Carmelo Casconefa421582018-09-13 10:05:57 -0700172 TrafficSelector srcSelector = DefaultTrafficSelector.builder()
173 .matchPi(ingressCriterion)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900174 .build();
Carmelo Casconefa421582018-09-13 10:05:57 -0700175 PiAction setSourceAct = PiAction.builder()
176 .withId(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_INT_SET_SOURCE)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900177 .build();
Carmelo Casconefa421582018-09-13 10:05:57 -0700178 TrafficTreatment srcTreatment = DefaultTrafficTreatment.builder()
179 .piTableAction(setSourceAct)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900180 .build();
Carmelo Casconefa421582018-09-13 10:05:57 -0700181 FlowRule srcFlowRule = DefaultFlowRule.builder()
182 .withSelector(srcSelector)
183 .withTreatment(srcTreatment)
184 .fromApp(appId)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900185 .withPriority(DEFAULT_PRIORITY)
186 .makePermanent()
187 .forDevice(deviceId)
Carmelo Casconefa421582018-09-13 10:05:57 -0700188 .forTable(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SOURCE)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900189 .build();
Carmelo Casconefa421582018-09-13 10:05:57 -0700190 flowRuleService.applyFlowRules(srcFlowRule);
191 return true;
192 }
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900193
Carmelo Casconefa421582018-09-13 10:05:57 -0700194 @Override
195 public boolean setSinkPort(PortNumber port) {
196
197 if (!setupBehaviour()) {
198 return false;
199 }
200
201 PiCriterion egressCriterion = PiCriterion.builder()
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800202 .matchExact(FabricConstants.HDR_EG_PORT, port.toLong())
Carmelo Casconefa421582018-09-13 10:05:57 -0700203 .build();
204 TrafficSelector sinkSelector = DefaultTrafficSelector.builder()
205 .matchPi(egressCriterion)
206 .build();
207 PiAction setSinkAct = PiAction.builder()
208 .withId(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_INT_SET_SINK)
209 .build();
210 TrafficTreatment sinkTreatment = DefaultTrafficTreatment.builder()
211 .piTableAction(setSinkAct)
212 .build();
213 FlowRule sinkFlowRule = DefaultFlowRule.builder()
214 .withSelector(sinkSelector)
215 .withTreatment(sinkTreatment)
216 .fromApp(appId)
217 .withPriority(DEFAULT_PRIORITY)
218 .makePermanent()
219 .forDevice(deviceId)
220 .forTable(FabricConstants.FABRIC_INGRESS_PROCESS_SET_SOURCE_SINK_TB_SET_SINK)
221 .build();
222 flowRuleService.applyFlowRules(sinkFlowRule);
223 return true;
224 }
225
226 @Override
227 public boolean addIntObjective(IntObjective obj) {
228
229 if (!setupBehaviour()) {
230 return false;
231 }
232
233 return processIntObjective(obj, true);
234 }
235
236 @Override
237 public boolean removeIntObjective(IntObjective obj) {
238
239 if (!setupBehaviour()) {
240 return false;
241 }
242
243 return processIntObjective(obj, false);
244 }
245
246 @Override
247 public boolean setupIntConfig(IntConfig config) {
248
249 if (!setupBehaviour()) {
250 return false;
251 }
252
253 return setupIntReportInternal(config);
254 }
255
256 @Override
257 public void cleanup() {
258
259 if (!setupBehaviour()) {
260 return;
261 }
262
263 StreamSupport.stream(flowRuleService.getFlowEntries(
264 data().deviceId()).spliterator(), false)
265 .filter(f -> f.table().type() == TableId.Type.PIPELINE_INDEPENDENT)
266 .filter(f -> TABLES_TO_CLEANUP.contains((PiTableId) f.table()))
267 .forEach(flowRuleService::removeFlowRules);
268 }
269
270 @Override
271 public boolean supportsFunctionality(IntFunctionality functionality) {
272 // Sink not fully supported yet.
273 return functionality == IntFunctionality.SOURCE || functionality == IntFunctionality.TRANSIT;
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900274 }
275
276 private FlowRule buildWatchlistEntry(IntObjective obj) {
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900277 int instructionBitmap = buildInstructionBitmap(obj.metadataTypes());
278 PiActionParam maxHopParam = new PiActionParam(
279 FabricConstants.MAX_HOP,
Carmelo Casconefa421582018-09-13 10:05:57 -0700280 copyFrom(MAXHOP));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900281 PiActionParam instCntParam = new PiActionParam(
282 FabricConstants.INS_CNT,
Carmelo Casconefa421582018-09-13 10:05:57 -0700283 copyFrom(Integer.bitCount(instructionBitmap)));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900284 PiActionParam inst0003Param = new PiActionParam(
285 FabricConstants.INS_MASK0003,
Carmelo Casconefa421582018-09-13 10:05:57 -0700286 copyFrom((instructionBitmap >> 12) & 0xF));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900287 PiActionParam inst0407Param = new PiActionParam(
288 FabricConstants.INS_MASK0407,
Carmelo Casconefa421582018-09-13 10:05:57 -0700289 copyFrom((instructionBitmap >> 8) & 0xF));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900290
291 PiAction intSourceAction = PiAction.builder()
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700292 .withId(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_SOURCE_INT_SOURCE_DSCP)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900293 .withParameter(maxHopParam)
294 .withParameter(instCntParam)
295 .withParameter(inst0003Param)
296 .withParameter(inst0407Param)
297 .build();
298
299 TrafficTreatment instTreatment = DefaultTrafficTreatment.builder()
300 .piTableAction(intSourceAction)
301 .build();
302
303 TrafficSelector.Builder sBuilder = DefaultTrafficSelector.builder();
304 for (Criterion criterion : obj.selector().criteria()) {
305 switch (criterion.type()) {
306 case IPV4_SRC:
307 sBuilder.matchIPSrc(((IPCriterion) criterion).ip());
308 break;
309 case IPV4_DST:
310 sBuilder.matchIPDst(((IPCriterion) criterion).ip());
311 break;
312 case TCP_SRC:
313 sBuilder.matchPi(
314 PiCriterion.builder().matchTernary(
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800315 FabricConstants.HDR_L4_SPORT,
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900316 ((TcpPortCriterion) criterion).tcpPort().toInt(), PORTMASK)
317 .build());
318 break;
319 case UDP_SRC:
320 sBuilder.matchPi(
321 PiCriterion.builder().matchTernary(
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800322 FabricConstants.HDR_L4_SPORT,
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900323 ((UdpPortCriterion) criterion).udpPort().toInt(), PORTMASK)
324 .build());
325 break;
326 case TCP_DST:
327 sBuilder.matchPi(
328 PiCriterion.builder().matchTernary(
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800329 FabricConstants.HDR_L4_DPORT,
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900330 ((TcpPortCriterion) criterion).tcpPort().toInt(), PORTMASK)
331 .build());
332 break;
333 case UDP_DST:
334 sBuilder.matchPi(
335 PiCriterion.builder().matchTernary(
Carmelo Casconeb5324e72018-11-25 02:26:32 -0800336 FabricConstants.HDR_L4_DPORT,
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900337 ((UdpPortCriterion) criterion).udpPort().toInt(), PORTMASK)
338 .build());
339 break;
340 default:
341 log.warn("Unsupported criterion type: {}", criterion.type());
342 }
343 }
344
345 return DefaultFlowRule.builder()
Carmelo Casconefa421582018-09-13 10:05:57 -0700346 .forDevice(deviceId)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900347 .withSelector(sBuilder.build())
348 .withTreatment(instTreatment)
349 .withPriority(DEFAULT_PRIORITY)
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700350 .forTable(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_SOURCE_TB_INT_SOURCE)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900351 .fromApp(appId)
Carmelo Casconefa421582018-09-13 10:05:57 -0700352 .makePermanent()
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900353 .build();
354 }
355
356 private int buildInstructionBitmap(Set<IntIntent.IntMetadataType> metadataTypes) {
357 int instBitmap = 0;
358 for (IntIntent.IntMetadataType metadataType : metadataTypes) {
359 switch (metadataType) {
360 case SWITCH_ID:
361 instBitmap |= (1 << 15);
362 break;
363 case L1_PORT_ID:
364 instBitmap |= (1 << 14);
365 break;
366 case HOP_LATENCY:
367 instBitmap |= (1 << 13);
368 break;
369 case QUEUE_OCCUPANCY:
370 instBitmap |= (1 << 12);
371 break;
372 case INGRESS_TIMESTAMP:
373 instBitmap |= (1 << 11);
374 break;
375 case EGRESS_TIMESTAMP:
376 instBitmap |= (1 << 10);
377 break;
378 case L2_PORT_ID:
379 instBitmap |= (1 << 9);
380 break;
381 case EGRESS_TX_UTIL:
382 instBitmap |= (1 << 8);
383 break;
384 default:
385 log.info("Unsupported metadata type {}. Ignoring...", metadataType);
386 break;
387 }
388 }
389 return instBitmap;
390 }
391
392 /**
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700393 * Returns a subset of Criterion from given selector, which is unsupported
394 * by this INT pipeline.
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900395 *
396 * @param selector a traffic selector
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700397 * @return a subset of Criterion from given selector, unsupported by this
398 * INT pipeline, empty if all criteria are supported.
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900399 */
400 private Set<Criterion> unsupportedSelectors(TrafficSelector selector) {
401 return selector.criteria().stream()
402 .filter(criterion -> !SUPPORTED_CRITERION.contains(criterion.type()))
403 .collect(Collectors.toSet());
404 }
405
406 private boolean processIntObjective(IntObjective obj, boolean install) {
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900407 if (install && !unsupportedSelectors(obj.selector()).isEmpty()) {
Carmelo Casconefa421582018-09-13 10:05:57 -0700408 log.warn("Criteria {} not supported by {} for INT watchlist",
409 unsupportedSelectors(obj.selector()), deviceId);
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900410 return false;
411 }
412
413 FlowRule flowRule = buildWatchlistEntry(obj);
414 if (flowRule != null) {
415 if (install) {
416 flowRuleService.applyFlowRules(flowRule);
417 } else {
418 flowRuleService.removeFlowRules(flowRule);
419 }
420 log.debug("IntObjective {} has been {} {}",
421 obj, install ? "installed to" : "removed from", deviceId);
422 return true;
423 } else {
424 log.warn("Failed to {} IntObjective {} on {}",
425 install ? "install" : "remove", obj, deviceId);
426 return false;
427 }
428 }
429
430 private boolean setupIntReportInternal(IntConfig cfg) {
Carmelo Casconefa421582018-09-13 10:05:57 -0700431 // Report not fully supported yet.
432 return true;
433 // FlowRule reportRule = buildReportEntry(cfg, PKT_INSTANCE_TYPE_INGRESS_CLONE);
434 // if (reportRule != null) {
435 // flowRuleService.applyFlowRules(reportRule);
436 // log.info("Report entry {} has been added to {}", reportRule, this.data().deviceId());
437 // return true;
438 // } else {
439 // log.warn("Failed to add report entry on {}", this.data().deviceId());
440 // return false;
441 // }
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900442 }
443
444 private FlowRule buildReportEntry(IntConfig cfg, int type) {
Carmelo Casconefa421582018-09-13 10:05:57 -0700445
446 if (!setupBehaviour()) {
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900447 return null;
448 }
449
450 PiActionParam srcMacParam = new PiActionParam(
451 FabricConstants.SRC_MAC,
Carmelo Casconefa421582018-09-13 10:05:57 -0700452 copyFrom(cfg.sinkMac().toBytes()));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900453 PiActionParam nextHopMacParam = new PiActionParam(
454 FabricConstants.MON_MAC,
Carmelo Casconefa421582018-09-13 10:05:57 -0700455 copyFrom(cfg.collectorNextHopMac().toBytes()));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900456 PiActionParam srcIpParam = new PiActionParam(
457 FabricConstants.SRC_IP,
Carmelo Casconefa421582018-09-13 10:05:57 -0700458 copyFrom(cfg.sinkIp().toOctets()));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900459 PiActionParam monIpParam = new PiActionParam(
460 FabricConstants.MON_IP,
Carmelo Casconefa421582018-09-13 10:05:57 -0700461 copyFrom(cfg.collectorIp().toOctets()));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900462 PiActionParam monPortParam = new PiActionParam(
463 FabricConstants.MON_PORT,
Carmelo Casconefa421582018-09-13 10:05:57 -0700464 copyFrom(cfg.collectorPort().toInt()));
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900465 PiAction reportAction = PiAction.builder()
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700466 .withId(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_REPORT_DO_REPORT_ENCAPSULATION)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900467 .withParameter(srcMacParam)
468 .withParameter(nextHopMacParam)
469 .withParameter(srcIpParam)
470 .withParameter(monIpParam)
471 .withParameter(monPortParam)
472 .build();
473 TrafficTreatment treatment = DefaultTrafficTreatment.builder()
474 .piTableAction(reportAction)
475 .build();
476
477 return DefaultFlowRule.builder()
478 .withTreatment(treatment)
479 .fromApp(appId)
480 .withPriority(DEFAULT_PRIORITY)
481 .makePermanent()
482 .forDevice(this.data().deviceId())
Carmelo Cascone79a3a312018-08-16 17:14:43 -0700483 .forTable(FabricConstants.FABRIC_EGRESS_PROCESS_INT_MAIN_PROCESS_INT_REPORT_TB_GENERATE_REPORT)
Jonghwan Hyuned478dc2018-08-06 15:35:18 +0900484 .build();
485 }
486
487}