Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | |
| 17 | package org.onosproject.t3.api; |
| 18 | |
| 19 | import org.onosproject.net.ConnectPoint; |
| 20 | import org.onosproject.net.flow.TrafficSelector; |
| 21 | import org.onosproject.net.group.Group; |
| 22 | |
| 23 | import java.util.List; |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 24 | import java.util.Objects; |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Class to represent the groups in a device for a given output and packet. |
| 28 | */ |
Andrea Campanella | e679801 | 2018-02-06 15:46:52 +0100 | [diff] [blame] | 29 | //FIXME consider name change. |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 30 | public class GroupsInDevice { |
| 31 | |
| 32 | private ConnectPoint output; |
| 33 | private List<Group> groups; |
| 34 | private TrafficSelector selector; |
| 35 | |
| 36 | /** |
| 37 | * Saves the given groups for the output connect point and the selector. |
Andrea Campanella | e679801 | 2018-02-06 15:46:52 +0100 | [diff] [blame] | 38 | * |
| 39 | * @param output the output connect point |
| 40 | * @param groups the groups |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 41 | * @param selector the selector representing the final packet |
| 42 | */ |
| 43 | public GroupsInDevice(ConnectPoint output, List<Group> groups, TrafficSelector selector) { |
| 44 | |
| 45 | this.output = output; |
| 46 | this.groups = groups; |
| 47 | this.selector = selector; |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Returns the output connect point. |
Andrea Campanella | e679801 | 2018-02-06 15:46:52 +0100 | [diff] [blame] | 52 | * |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 53 | * @return the connect point |
| 54 | */ |
| 55 | public ConnectPoint getOutput() { |
| 56 | return output; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Returns the groups. |
Andrea Campanella | e679801 | 2018-02-06 15:46:52 +0100 | [diff] [blame] | 61 | * |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 62 | * @return groups. |
| 63 | */ |
| 64 | public List<Group> getGroups() { |
| 65 | return groups; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Returns the final packet after traversing the network. |
Andrea Campanella | e679801 | 2018-02-06 15:46:52 +0100 | [diff] [blame] | 70 | * |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 71 | * @return the selector with packet info |
| 72 | */ |
| 73 | public TrafficSelector getFinalPacket() { |
| 74 | return selector; |
| 75 | } |
| 76 | |
Andrea Campanella | e679801 | 2018-02-06 15:46:52 +0100 | [diff] [blame] | 77 | /** |
| 78 | * Updates the final packet. |
| 79 | * |
| 80 | * @param updatedPacket the updated final packet |
| 81 | */ |
| 82 | public void setFinalPacket(TrafficSelector updatedPacket) { |
| 83 | selector = updatedPacket; |
| 84 | } |
| 85 | |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 86 | @Override |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 87 | public boolean equals(Object o) { |
| 88 | if (this == o) { |
| 89 | return true; |
| 90 | } |
| 91 | |
| 92 | if (o == null || getClass() != o.getClass()) { |
| 93 | return false; |
| 94 | } |
| 95 | |
| 96 | GroupsInDevice that = (GroupsInDevice) o; |
| 97 | |
| 98 | return Objects.equals(output, that.output) && |
| 99 | Objects.equals(groups, that.groups) && |
| 100 | Objects.equals(selector, that.selector); |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public int hashCode() { |
| 105 | return Objects.hash(output, groups, selector); |
| 106 | } |
| 107 | |
| 108 | @Override |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 109 | public String toString() { |
| 110 | return "GroupsInDevice{" + |
Andrea Campanella | 696ef03 | 2018-02-27 18:03:17 +0100 | [diff] [blame] | 111 | |
Andrea Campanella | e408440 | 2017-12-15 15:27:31 +0100 | [diff] [blame] | 112 | "output=" + output + |
| 113 | ", groups=" + groups + |
| 114 | ", selector=" + selector + |
| 115 | '}'; |
| 116 | } |
| 117 | |
| 118 | } |