Carmelo Cascone | 2cad9ef | 2017-08-01 21:52:07 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 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.p4runtime.ctl; |
| 18 | |
| 19 | import com.google.common.base.MoreObjects; |
| 20 | import com.google.common.base.Objects; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.pi.runtime.PiPacketOperation; |
| 23 | import org.onosproject.p4runtime.api.P4RuntimePacketIn; |
| 24 | |
| 25 | import static com.google.common.base.Preconditions.checkNotNull; |
| 26 | |
| 27 | /** |
| 28 | * Default implementation of a packet-in in P4Runtime. |
| 29 | */ |
| 30 | final class DefaultPacketIn implements P4RuntimePacketIn { |
| 31 | |
| 32 | private final DeviceId deviceId; |
| 33 | private final PiPacketOperation operation; |
| 34 | |
| 35 | DefaultPacketIn(DeviceId deviceId, PiPacketOperation operation) { |
| 36 | this.deviceId = checkNotNull(deviceId); |
| 37 | this.operation = checkNotNull(operation); |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public DeviceId deviceId() { |
| 42 | return deviceId; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public PiPacketOperation packetOperation() { |
| 47 | return operation; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public boolean equals(Object o) { |
| 52 | if (this == o) { |
| 53 | return true; |
| 54 | } |
| 55 | if (o == null || getClass() != o.getClass()) { |
| 56 | return false; |
| 57 | } |
| 58 | DefaultPacketIn that = (DefaultPacketIn) o; |
| 59 | return Objects.equal(deviceId, that.deviceId) && |
| 60 | Objects.equal(operation, that.operation); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public int hashCode() { |
| 65 | return Objects.hashCode(deviceId, operation); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public String toString() { |
| 70 | return MoreObjects.toStringHelper(this) |
| 71 | .add("deviceId", deviceId) |
| 72 | .add("operation", operation) |
| 73 | .toString(); |
| 74 | } |
| 75 | } |