pierventre | b58e9c9 | 2020-05-22 09:42:31 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.net; |
| 18 | |
| 19 | import com.google.common.collect.Lists; |
| 20 | import com.google.common.collect.Maps; |
| 21 | import org.onosproject.core.GroupId; |
| 22 | import org.onosproject.net.flow.FlowEntry; |
pierventre | b58e9c9 | 2020-05-22 09:42:31 -0700 | [diff] [blame] | 23 | import org.onosproject.net.group.Group; |
| 24 | |
| 25 | import java.util.List; |
| 26 | import java.util.Map; |
| 27 | |
| 28 | /** |
| 29 | * Represents the input of the pipeline traceable processing. |
| 30 | */ |
pierventre | 6fa8cd6 | 2020-10-08 17:21:49 +0200 | [diff] [blame] | 31 | public final class PipelineTraceableInput { |
pierventre | b58e9c9 | 2020-05-22 09:42:31 -0700 | [diff] [blame] | 32 | |
| 33 | // Input state for the traceable behavior |
pierventre | 6fa8cd6 | 2020-10-08 17:21:49 +0200 | [diff] [blame] | 34 | private PipelineTraceablePacket ingressPacket; |
| 35 | private ConnectPoint ingressPort; |
pierventre | b58e9c9 | 2020-05-22 09:42:31 -0700 | [diff] [blame] | 36 | // List here all possible device state using |
| 37 | // possibly an optimized reference |
pierventre | 6fa8cd6 | 2020-10-08 17:21:49 +0200 | [diff] [blame] | 38 | private List<FlowEntry> flows = Lists.newArrayList(); |
| 39 | private Map<GroupId, Group> groups = Maps.newHashMap(); |
| 40 | private List<DataPlaneEntity> deviceState; |
pierventre | b58e9c9 | 2020-05-22 09:42:31 -0700 | [diff] [blame] | 41 | |
pierventre | 6fa8cd6 | 2020-10-08 17:21:49 +0200 | [diff] [blame] | 42 | /** |
| 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, |
pierventre | b58e9c9 | 2020-05-22 09:42:31 -0700 | [diff] [blame] | 50 | List<DataPlaneEntity> deviceState) { |
| 51 | this.ingressPacket = ingressPacket; |
| 52 | this.ingressPort = ingressPort; |
pierventre | 6fa8cd6 | 2020-10-08 17:21:49 +0200 | [diff] [blame] | 53 | this.deviceState = deviceState; |
pierventre | b58e9c9 | 2020-05-22 09:42:31 -0700 | [diff] [blame] | 54 | 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 | */ |
pierventre | 6fa8cd6 | 2020-10-08 17:21:49 +0200 | [diff] [blame] | 73 | public PipelineTraceablePacket ingressPacket() { |
pierventre | b58e9c9 | 2020-05-22 09:42:31 -0700 | [diff] [blame] | 74 | 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 | /** |
pierventre | 6fa8cd6 | 2020-10-08 17:21:49 +0200 | [diff] [blame] | 87 | * Getter for the device state. |
| 88 | * |
| 89 | * @return the device state |
| 90 | */ |
| 91 | public List<DataPlaneEntity> deviceState() { |
| 92 | return deviceState; |
| 93 | } |
| 94 | |
| 95 | /** |
pierventre | b58e9c9 | 2020-05-22 09:42:31 -0700 | [diff] [blame] | 96 | * 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 | */ |
pierventre | 6fa8cd6 | 2020-10-08 17:21:49 +0200 | [diff] [blame] | 119 | public Group groupById(GroupId groupId) { |
pierventre | b58e9c9 | 2020-05-22 09:42:31 -0700 | [diff] [blame] | 120 | return groups.get(groupId); |
| 121 | } |
| 122 | |
| 123 | } |