Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [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 | |
Carmelo Cascone | a966c34 | 2017-07-30 01:56:30 -0400 | [diff] [blame] | 19 | import com.google.common.base.MoreObjects; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 20 | import com.google.common.base.Objects; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 21 | import org.onosproject.event.AbstractEvent; |
| 22 | import org.onosproject.net.DeviceId; |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 23 | import org.onosproject.net.pi.runtime.PiPacketOperation; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 24 | import org.onosproject.p4runtime.api.P4RuntimeEvent; |
| 25 | import org.onosproject.p4runtime.api.P4RuntimeEventListener; |
| 26 | import org.onosproject.p4runtime.api.P4RuntimeEventSubject; |
| 27 | import org.onosproject.p4runtime.api.P4RuntimePacketIn; |
| 28 | |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 29 | import static com.google.common.base.Preconditions.checkNotNull; |
| 30 | |
| 31 | /** |
| 32 | * Default implementation of a packet-in event. |
| 33 | */ |
| 34 | final class DefaultPacketInEvent |
| 35 | extends AbstractEvent<P4RuntimeEventListener.Type, P4RuntimeEventSubject> |
| 36 | implements P4RuntimeEvent { |
| 37 | |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 38 | DefaultPacketInEvent(DeviceId deviceId, PiPacketOperation operation) { |
| 39 | super(P4RuntimeEventListener.Type.PACKET_IN, new DefaultPacketIn(deviceId, operation)); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Default implementation of a packet-in in P4Runtime. |
| 44 | */ |
| 45 | private static final class DefaultPacketIn implements P4RuntimePacketIn { |
| 46 | |
| 47 | private final DeviceId deviceId; |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 48 | private final PiPacketOperation operation; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 49 | |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 50 | private DefaultPacketIn(DeviceId deviceId, PiPacketOperation operation) { |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 51 | this.deviceId = checkNotNull(deviceId); |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 52 | this.operation = checkNotNull(operation); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public DeviceId deviceId() { |
| 57 | return deviceId; |
| 58 | } |
| 59 | |
| 60 | @Override |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 61 | public PiPacketOperation packetOperation() { |
| 62 | return operation; |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public boolean equals(Object o) { |
| 67 | if (this == o) { |
| 68 | return true; |
| 69 | } |
| 70 | if (o == null || getClass() != o.getClass()) { |
| 71 | return false; |
| 72 | } |
| 73 | DefaultPacketIn that = (DefaultPacketIn) o; |
| 74 | return Objects.equal(deviceId, that.deviceId) && |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 75 | Objects.equal(operation, that.operation); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public int hashCode() { |
Andrea Campanella | 288b273 | 2017-07-28 14:16:16 +0200 | [diff] [blame] | 80 | return Objects.hashCode(deviceId, operation); |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 81 | } |
Carmelo Cascone | a966c34 | 2017-07-30 01:56:30 -0400 | [diff] [blame] | 82 | |
| 83 | @Override |
| 84 | public String toString() { |
| 85 | return MoreObjects.toStringHelper(this) |
| 86 | .add("deviceId", deviceId) |
| 87 | .add("operation", operation) |
| 88 | .toString(); |
| 89 | } |
Carmelo Cascone | f7aa3f9 | 2017-07-06 23:56:50 -0400 | [diff] [blame] | 90 | } |
| 91 | } |