blob: 2403c5ee88a02545d90762d20e91d5d263c63dcf [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;
23import org.onosproject.net.flow.TrafficSelector;
24import org.onosproject.net.group.Group;
25
26import java.util.List;
27import java.util.Map;
28
29/**
30 * Represents the input of the pipeline traceable processing.
31 */
32public class PipelineTraceableInput {
33
34 // Input state for the traceable behavior
35 TrafficSelector ingressPacket;
36 ConnectPoint ingressPort;
37 // List here all possible device state using
38 // possibly an optimized reference
39 List<FlowEntry> flows = Lists.newArrayList();
40 Map<GroupId, Group> groups = Maps.newHashMap();
41
42 public PipelineTraceableInput(TrafficSelector ingressPacket, ConnectPoint ingressPort,
43 List<DataPlaneEntity> deviceState) {
44 this.ingressPacket = ingressPacket;
45 this.ingressPort = ingressPort;
46 processDeviceState(deviceState);
47 }
48
49 // Init internal device state (flows, groups, etc)
50 private void processDeviceState(List<DataPlaneEntity> deviceState) {
51 deviceState.forEach(entity -> {
52 if (entity.getType() == DataPlaneEntity.Type.FLOWRULE) {
53 flows.add(entity.getFlowEntry());
54 } else if (entity.getType() == DataPlaneEntity.Type.GROUP) {
55 groups.put(entity.getGroupEntry().id(), entity.getGroupEntry());
56 }
57 });
58 }
59
60 /**
61 * Getter for the ingress packet.
62 *
63 * @return the ingress packet
64 */
65 public TrafficSelector ingressPacket() {
66 return ingressPacket;
67 }
68
69 /**
70 * Getter for the ingress port.
71 *
72 * @return the ingress port
73 */
74 public ConnectPoint ingressPort() {
75 return ingressPort;
76 }
77
78 /**
79 * Getter for the flows.
80 *
81 * @return the flows
82 */
83 public List<FlowEntry> flows() {
84 return flows;
85 }
86
87 /**
88 * Getter for the groups.
89 *
90 * @return the groups
91 */
92 public Map<GroupId, Group> groups() {
93 return groups;
94 }
95
96 /**
97 * Returns the group associated with the given group id.
98 *
99 * @param groupId the group id
100 * @return the group, otherwise null.
101 */
102 public Group getGroup(GroupId groupId) {
103 return groups.get(groupId);
104 }
105
106}