blob: 501357c7376d7703d497631a6fbf90cef7d5e251 [file] [log] [blame]
Harshada Chaundkardcd1b142019-03-25 17:27:44 -04001/*
2 * Copyright 2019-present Open Networking Foundation
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 */
16package org.onosproject.net.packet.packetfilter;
17
18import org.onlab.packet.Ethernet;
19import org.onlab.packet.ICMP;
20import org.onlab.packet.IPv4;
21import org.onosproject.net.packet.PacketContext;
22import org.onosproject.net.packet.PacketInClassifier;
23
24public class IcmpPacketClassifier implements PacketInClassifier {
25
26 @Override
27 public boolean match(PacketContext packet) {
28
29 Ethernet eth = packet.inPacket().parsed();
30
31 if (eth.getEtherType() == Ethernet.TYPE_IPV4) {
32 IPv4 ipv4Packet = (IPv4) eth.getPayload();
33
34 if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
35 ICMP icmpPacket = (ICMP) ipv4Packet.getPayload();
36 if (icmpPacket.getIcmpType() == ICMP.TYPE_ECHO_REQUEST) {
37 return true;
38 }
39 }
40 }
41 return false;
42 }
43}