blob: 8df5d95c467459a4e19147aabdc3583c204fe5ef [file] [log] [blame]
pierventre4b72c472020-05-22 09:42:31 -07001/*
2 * Copyright 2020-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 */
16
17package org.onosproject.net;
18
19import com.google.common.collect.Lists;
20import com.google.common.collect.Maps;
21import org.onosproject.core.GroupId;
22import org.onosproject.net.flow.FlowEntry;
pierventre4b72c472020-05-22 09:42:31 -070023import org.onosproject.net.group.Group;
24
25import java.util.List;
26import java.util.Map;
27
28/**
29 * Represents the input of the pipeline traceable processing.
30 */
pierventre26eb65d2020-10-08 17:21:49 +020031public final class PipelineTraceableInput {
pierventre4b72c472020-05-22 09:42:31 -070032
33 // Input state for the traceable behavior
pierventre26eb65d2020-10-08 17:21:49 +020034 private PipelineTraceablePacket ingressPacket;
35 private ConnectPoint ingressPort;
pierventre4b72c472020-05-22 09:42:31 -070036 // List here all possible device state using
37 // possibly an optimized reference
pierventre26eb65d2020-10-08 17:21:49 +020038 private List<FlowEntry> flows = Lists.newArrayList();
39 private Map<GroupId, Group> groups = Maps.newHashMap();
40 private List<DataPlaneEntity> deviceState;
pierventre4b72c472020-05-22 09:42:31 -070041
pierventre26eb65d2020-10-08 17:21:49 +020042 /**
43 * Builds a pipeline traceable input.
44 *
45 * @param ingressPacket the input packet
46 * @param ingressPort the input port
47 * @param deviceState the device state
48 */
49 public PipelineTraceableInput(PipelineTraceablePacket ingressPacket, ConnectPoint ingressPort,
pierventre4b72c472020-05-22 09:42:31 -070050 List<DataPlaneEntity> deviceState) {
51 this.ingressPacket = ingressPacket;
52 this.ingressPort = ingressPort;
pierventre26eb65d2020-10-08 17:21:49 +020053 this.deviceState = deviceState;
pierventre4b72c472020-05-22 09:42:31 -070054 processDeviceState(deviceState);
55 }
56
57 // Init internal device state (flows, groups, etc)
58 private void processDeviceState(List<DataPlaneEntity> deviceState) {
59 deviceState.forEach(entity -> {
60 if (entity.getType() == DataPlaneEntity.Type.FLOWRULE) {
61 flows.add(entity.getFlowEntry());
62 } else if (entity.getType() == DataPlaneEntity.Type.GROUP) {
63 groups.put(entity.getGroupEntry().id(), entity.getGroupEntry());
64 }
65 });
66 }
67
68 /**
69 * Getter for the ingress packet.
70 *
71 * @return the ingress packet
72 */
pierventre26eb65d2020-10-08 17:21:49 +020073 public PipelineTraceablePacket ingressPacket() {
pierventre4b72c472020-05-22 09:42:31 -070074 return ingressPacket;
75 }
76
77 /**
78 * Getter for the ingress port.
79 *
80 * @return the ingress port
81 */
82 public ConnectPoint ingressPort() {
83 return ingressPort;
84 }
85
86 /**
pierventre26eb65d2020-10-08 17:21:49 +020087 * Getter for the device state.
88 *
89 * @return the device state
90 */
91 public List<DataPlaneEntity> deviceState() {
92 return deviceState;
93 }
94
95 /**
pierventre4b72c472020-05-22 09:42:31 -070096 * Getter for the flows.
97 *
98 * @return the flows
99 */
100 public List<FlowEntry> flows() {
101 return flows;
102 }
103
104 /**
105 * Getter for the groups.
106 *
107 * @return the groups
108 */
109 public Map<GroupId, Group> groups() {
110 return groups;
111 }
112
113 /**
114 * Returns the group associated with the given group id.
115 *
116 * @param groupId the group id
117 * @return the group, otherwise null.
118 */
pierventre26eb65d2020-10-08 17:21:49 +0200119 public Group groupById(GroupId groupId) {
pierventre4b72c472020-05-22 09:42:31 -0700120 return groups.get(groupId);
121 }
122
123}