blob: a320a449754f2cf3d221748659cb0b238417c64b [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.DHCP6;
19import org.onlab.packet.Ethernet;
20import org.onlab.packet.IPv6;
21import org.onlab.packet.UDP;
22import org.onosproject.net.packet.PacketContext;
23import org.onosproject.net.packet.PacketInClassifier;
24import org.slf4j.Logger;
25import static org.slf4j.LoggerFactory.getLogger;
26
27public class Dhcp6DirectPacketClassifier implements PacketInClassifier {
28 private final Logger log = getLogger(getClass());
29 @Override
30 public boolean match(PacketContext packet) {
31
32 Ethernet eth = packet.inPacket().parsed();
33
34 if (eth.getEtherType() == Ethernet.TYPE_IPV6) {
35 IPv6 ipv6Packet = (IPv6) eth.getPayload();
36
37 if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_UDP) {
38 UDP udpPacket = (UDP) ipv6Packet.getPayload();
39 //Directly connected host
40 if (udpPacket.getDestinationPort() == UDP.DHCP_V6_SERVER_PORT &&
41 udpPacket.getSourcePort() == UDP.DHCP_V6_CLIENT_PORT) {
42 DHCP6 dhcp6 = (DHCP6) udpPacket.getPayload();
43 if (dhcp6.getMsgType() == DHCP6.MsgType.SOLICIT.value()) {
44 return true;
45 }
46 }
47 }
48 }
49 return false;
50 }
51}