blob: 7dfa806f3b8c7ce58539fe859f16eed93c1469e3 [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.ICMP6;
20import org.onlab.packet.IPv6;
21import org.onosproject.net.packet.PacketContext;
22import org.onosproject.net.packet.PacketInClassifier;
23import org.slf4j.Logger;
24import static org.slf4j.LoggerFactory.getLogger;
25
26public class Icmp6PacketClassifier implements PacketInClassifier {
27 private final Logger log = getLogger(getClass());
28 @Override
29 public boolean match(PacketContext packet) {
30 Ethernet eth = packet.inPacket().parsed();
31
32 if (eth.getEtherType() == Ethernet.TYPE_IPV6) {
33 IPv6 ipv6Packet = (IPv6) eth.getPayload();
34
35 if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
36 ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
37 if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST) {
38 return true;
39 }
40 }
41 }
42 return false;
43 }
44}