Andrea Campanella | bb66e09 | 2019-01-28 13:50:06 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2019-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 | * This work was partially supported by EC H2020 project METRO-HAUL (761727). |
| 17 | */ |
| 18 | package org.onosproject.drivers.odtn.impl; |
| 19 | |
| 20 | import org.onosproject.net.flow.FlowRule; |
| 21 | |
| 22 | import java.util.Objects; |
| 23 | |
| 24 | /** |
| 25 | * Connection consisting of a unique identifier of the connection on the device and the corresponding rule within ONOS. |
| 26 | */ |
| 27 | public final class DeviceConnection { |
| 28 | |
| 29 | private String id; |
| 30 | private FlowRule fr; |
| 31 | |
| 32 | //Avoiding public construction |
| 33 | private DeviceConnection(){} |
| 34 | |
| 35 | /** |
| 36 | * Creates the Device connection object. |
| 37 | * |
| 38 | * @param id the unique id of the connection on the device |
| 39 | * @param fr the flow rule in ONOS |
| 40 | */ |
| 41 | private DeviceConnection(String id, FlowRule fr) { |
| 42 | this.id = id; |
| 43 | this.fr = fr; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Creates the Device connection object. |
| 48 | * |
| 49 | * @param id the unique id of the connection on the device |
| 50 | * @param fr the flow rule in ONOS |
| 51 | * @return the DeviceConnection object. |
| 52 | */ |
| 53 | public static DeviceConnection of(String id, FlowRule fr) { |
| 54 | return new DeviceConnection(id, fr); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Gets the unique id of the connection on the device. |
| 59 | * E.g TAPI UUID of the connectivity service. |
| 60 | * |
| 61 | * @return the unique id on the device. |
| 62 | */ |
| 63 | public String getId() { |
| 64 | return id; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Gets the flow rule associated to the unique id on the device. |
| 69 | * The Flow Rule contains the info of the given connection as needed by ONOS. |
| 70 | * |
| 71 | * @return the flow rule |
| 72 | */ |
| 73 | public FlowRule getFlowRule() { |
| 74 | return fr; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public boolean equals(Object o) { |
| 79 | if (this == o) { |
| 80 | return true; |
| 81 | } |
| 82 | if (o == null || getClass() != o.getClass()) { |
| 83 | return false; |
| 84 | } |
| 85 | DeviceConnection that = (DeviceConnection) o; |
| 86 | return Objects.equals(id, that.id); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public int hashCode() { |
| 91 | return Objects.hash(id, fr); |
| 92 | } |
| 93 | } |