blob: 104999bc264031906808c2fce544727066dc578d [file] [log] [blame]
Carmelo Casconef7aa3f92017-07-06 23:56:50 -04001/*
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
17package org.onosproject.p4runtime.ctl;
18
19import com.google.common.base.Objects;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040020import org.onosproject.event.AbstractEvent;
21import org.onosproject.net.DeviceId;
Andrea Campanella288b2732017-07-28 14:16:16 +020022import org.onosproject.net.pi.runtime.PiPacketOperation;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040023import org.onosproject.p4runtime.api.P4RuntimeEvent;
24import org.onosproject.p4runtime.api.P4RuntimeEventListener;
25import org.onosproject.p4runtime.api.P4RuntimeEventSubject;
26import org.onosproject.p4runtime.api.P4RuntimePacketIn;
27
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040028import static com.google.common.base.Preconditions.checkNotNull;
29
30/**
31 * Default implementation of a packet-in event.
32 */
33final class DefaultPacketInEvent
34 extends AbstractEvent<P4RuntimeEventListener.Type, P4RuntimeEventSubject>
35 implements P4RuntimeEvent {
36
Andrea Campanella288b2732017-07-28 14:16:16 +020037 DefaultPacketInEvent(DeviceId deviceId, PiPacketOperation operation) {
38 super(P4RuntimeEventListener.Type.PACKET_IN, new DefaultPacketIn(deviceId, operation));
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040039 }
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 Campanella288b2732017-07-28 14:16:16 +020047 private final PiPacketOperation operation;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040048
Andrea Campanella288b2732017-07-28 14:16:16 +020049 private DefaultPacketIn(DeviceId deviceId, PiPacketOperation operation) {
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040050 this.deviceId = checkNotNull(deviceId);
Andrea Campanella288b2732017-07-28 14:16:16 +020051 this.operation = checkNotNull(operation);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040052 }
53
54 @Override
55 public DeviceId deviceId() {
56 return deviceId;
57 }
58
59 @Override
Andrea Campanella288b2732017-07-28 14:16:16 +020060 public PiPacketOperation packetOperation() {
61 return operation;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040062 }
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 Campanella288b2732017-07-28 14:16:16 +020074 Objects.equal(operation, that.operation);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040075 }
76
77 @Override
78 public int hashCode() {
Andrea Campanella288b2732017-07-28 14:16:16 +020079 return Objects.hashCode(deviceId, operation);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040080 }
81 }
82}