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; |
| 20 | import org.onlab.util.ImmutableByteSequence; |
| 21 | import org.onosproject.event.AbstractEvent; |
| 22 | import org.onosproject.net.DeviceId; |
| 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 | |
| 28 | import java.util.List; |
| 29 | |
| 30 | import static com.google.common.base.Preconditions.checkNotNull; |
| 31 | |
| 32 | /** |
| 33 | * Default implementation of a packet-in event. |
| 34 | */ |
| 35 | final class DefaultPacketInEvent |
| 36 | extends AbstractEvent<P4RuntimeEventListener.Type, P4RuntimeEventSubject> |
| 37 | implements P4RuntimeEvent { |
| 38 | |
| 39 | DefaultPacketInEvent(DeviceId deviceId, ImmutableByteSequence data, |
| 40 | List<ImmutableByteSequence> metadata) { |
| 41 | super(P4RuntimeEventListener.Type.PACKET_IN, new DefaultPacketIn(deviceId, data, metadata)); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Default implementation of a packet-in in P4Runtime. |
| 46 | */ |
| 47 | private static final class DefaultPacketIn implements P4RuntimePacketIn { |
| 48 | |
| 49 | private final DeviceId deviceId; |
| 50 | private final ImmutableByteSequence data; |
| 51 | private final List<ImmutableByteSequence> metadata; |
| 52 | |
| 53 | private DefaultPacketIn(DeviceId deviceId, ImmutableByteSequence data, List<ImmutableByteSequence> metadata) { |
| 54 | this.deviceId = checkNotNull(deviceId); |
| 55 | this.data = checkNotNull(data); |
| 56 | this.metadata = checkNotNull(metadata); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public DeviceId deviceId() { |
| 61 | return deviceId; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public ImmutableByteSequence data() { |
| 66 | return data; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public List<ImmutableByteSequence> metadata() { |
| 71 | return metadata; |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public boolean equals(Object o) { |
| 76 | if (this == o) { |
| 77 | return true; |
| 78 | } |
| 79 | if (o == null || getClass() != o.getClass()) { |
| 80 | return false; |
| 81 | } |
| 82 | DefaultPacketIn that = (DefaultPacketIn) o; |
| 83 | return Objects.equal(deviceId, that.deviceId) && |
| 84 | Objects.equal(data, that.data) && |
| 85 | Objects.equal(metadata, that.metadata); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public int hashCode() { |
| 90 | return Objects.hashCode(deviceId, data, metadata); |
| 91 | } |
| 92 | } |
| 93 | } |