blob: 1389c8c177efe9b9d406aa28029b7a1bfbfa5cfa [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.DHCP;
19import org.onlab.packet.Ethernet;
20import org.onlab.packet.IPv4;
21import org.onlab.packet.UDP;
22import org.onosproject.net.packet.PacketContext;
23import org.onosproject.net.packet.PacketInClassifier;
24
25public class DhcpPacketClassifier implements PacketInClassifier {
26
27 @Override
28 public boolean match(PacketContext packet) {
29
30 Ethernet eth = packet.inPacket().parsed();
31
32 if (eth.getEtherType() == Ethernet.TYPE_IPV4) {
33 IPv4 ipv4Packet = (IPv4) eth.getPayload();
34
35 if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_UDP) {
36 UDP udpPacket = (UDP) ipv4Packet.getPayload();
37
38 if (udpPacket.getDestinationPort() == UDP.DHCP_SERVER_PORT &&
39 udpPacket.getSourcePort() == UDP.DHCP_CLIENT_PORT) {
40 DHCP dhcp = (DHCP) udpPacket.getPayload();
41 if (dhcp.getPacketType() == DHCP.MsgType.DHCPDISCOVER) {
42 return true;
43 }
44 }
45 }
46 }
47 return false;
48 }
49
50
51}