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