blob: e0be1046674ad39cadf46c1b0a8950538cc9983c [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
Carmelo Casconea966c342017-07-30 01:56:30 -040019import com.google.common.base.MoreObjects;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040020import com.google.common.base.Objects;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040021import org.onosproject.event.AbstractEvent;
22import org.onosproject.net.DeviceId;
Andrea Campanella288b2732017-07-28 14:16:16 +020023import org.onosproject.net.pi.runtime.PiPacketOperation;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040024import org.onosproject.p4runtime.api.P4RuntimeEvent;
25import org.onosproject.p4runtime.api.P4RuntimeEventListener;
26import org.onosproject.p4runtime.api.P4RuntimeEventSubject;
27import org.onosproject.p4runtime.api.P4RuntimePacketIn;
28
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040029import static com.google.common.base.Preconditions.checkNotNull;
30
31/**
32 * Default implementation of a packet-in event.
33 */
34final class DefaultPacketInEvent
35 extends AbstractEvent<P4RuntimeEventListener.Type, P4RuntimeEventSubject>
36 implements P4RuntimeEvent {
37
Andrea Campanella288b2732017-07-28 14:16:16 +020038 DefaultPacketInEvent(DeviceId deviceId, PiPacketOperation operation) {
39 super(P4RuntimeEventListener.Type.PACKET_IN, new DefaultPacketIn(deviceId, operation));
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040040 }
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 Campanella288b2732017-07-28 14:16:16 +020048 private final PiPacketOperation operation;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040049
Andrea Campanella288b2732017-07-28 14:16:16 +020050 private DefaultPacketIn(DeviceId deviceId, PiPacketOperation operation) {
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040051 this.deviceId = checkNotNull(deviceId);
Andrea Campanella288b2732017-07-28 14:16:16 +020052 this.operation = checkNotNull(operation);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040053 }
54
55 @Override
56 public DeviceId deviceId() {
57 return deviceId;
58 }
59
60 @Override
Andrea Campanella288b2732017-07-28 14:16:16 +020061 public PiPacketOperation packetOperation() {
62 return operation;
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040063 }
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 Campanella288b2732017-07-28 14:16:16 +020075 Objects.equal(operation, that.operation);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040076 }
77
78 @Override
79 public int hashCode() {
Andrea Campanella288b2732017-07-28 14:16:16 +020080 return Objects.hashCode(deviceId, operation);
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040081 }
Carmelo Casconea966c342017-07-30 01:56:30 -040082
83 @Override
84 public String toString() {
85 return MoreObjects.toStringHelper(this)
86 .add("deviceId", deviceId)
87 .add("operation", operation)
88 .toString();
89 }
Carmelo Casconef7aa3f92017-07-06 23:56:50 -040090 }
91}