@Override
	public void RecvData(int sock, String Data) throws LowLinkException, TransportLayerException {
        DHCPPacket p = new DHCPPacket();
        String IP;
        
        p.fromBytes(Data);
        
        if(p.op == 1){
            switch(p.msgType){
                case 1:
                {
                    LayerInfo protInfo = new LayerInfo(getClass().getName());
                    protInfo.setObjectName(mParentStack.getParentNodeName());
                    protInfo.setDataType("DHCP Server");
                    protInfo.setLayer("Application ");
                    protInfo.setDescription("Recieved DHCPDISCOVER(xid=" + p.xid + ") from " + p.chaddr + " with op=1.");
                    Simulation.addLayerInfo(protInfo);
                    
                    IP = findLease(p.chaddr);
                    
                    if(IP!=""){
                    	leases.remove(p.chaddr);
                    }
                    
                    lease l = advertLease(p.chaddr);
                        
                        if(l.IP!=""){
                            l.xid = p.xid;
                            l.negotiation_started = (System.currentTimeMillis()/1000);

                            leases.put(l.IP, l);

                            DHCPPacket o = new DHCPPacket();

                            o.chaddr = p.chaddr;
                            o.msgType = 2;
                            o.DHCPServer = mParentStack.SL().get_socket(appSock).src_IP;
                            o.leaseTime = 3600;
                            o.yiaddr = l.IP;
                            o.op = 2;
                            l.xid = o.xid = p.xid;
                            o.SubnetMask = l.Genmask;
                            o.Gateway = l.Gateway;
                            
                            LayerInfo protInfo1 = new LayerInfo(getClass().getName());                            
                            protInfo1.setObjectName(mParentStack.getParentNodeName());
                            protInfo1.setDataType("DHCP Server");
                            protInfo1.setLayer("Application ");
                            protInfo1.setDescription("Sending DHCPOFFER(xid=" + o.xid + ") packet to 255.255.255.255 with op=1 chaddr='" +
                            o.chaddr + "' DHCP Server='" + o.DHCPServer + "' yiaddr='" + o.yiaddr + "'.");
                            Simulation.addLayerInfo(protInfo);

                            try{
                                SendData(appSock, "255.255.255.255", 68, o.toBytes());
                            }catch(CommunicationException e){
                                throw new TransportLayerException(e.toString());
                            }
                        }

                    
                     /*else if(check if leased yet ){
                     
                     }else{
                        
                     }
                    */
                }
                    break;
                case 3:
                    IP = findLease(p.chaddr);
                    
                    LayerInfo protInfo = new LayerInfo(getClass().getName());
                    protInfo.setObjectName(mParentStack.getParentNodeName());
                    protInfo.setDataType("DHCP Server");
                    protInfo.setLayer("Application ");
                    protInfo.setDescription("Recieved DHCPREQUEST(xid=" + p.xid + ") from " + p.chaddr + " with op=1 and preferred IP='" + p.WantedIP + "'.");
                    Simulation.addLayerInfo(protInfo);
                    
                    if(IP!=""){
                        lease l = leases.get(IP);
                        
                        if(l.xid == p.xid){
                            l.leased = (System.currentTimeMillis()/1000);
                            l.negotiation_started = 0;
                            l.completed = true;
                            
                            DHCPPacket o = new DHCPPacket();

                            o.chaddr = p.chaddr;
                            o.msgType = 5;
                            o.DHCPServer = mParentStack.SL().get_socket(appSock).src_IP;
                            o.leaseTime = 3600;
                            o.yiaddr = l.IP;
                            o.xid = l.xid;
                            o.op = 2;
                            o.SubnetMask = l.Genmask;
                            o.Gateway = l.Gateway;
                            o.WantedIP = "";                            
                            
                            protInfo = new LayerInfo(getClass().getName());
                            protInfo.setObjectName(mParentStack.getParentNodeName());
                            protInfo.setDataType("DHCP Server");
                            protInfo.setLayer("Application ");
                            protInfo.setDescription("Sending DHCPACK(xid=" + o.xid + ") packet to 255.255.255.255 with op=1 chaddr='" +
                            o.chaddr + "' DHCP Server='" + o.DHCPServer + "' yiaddr='" + o.yiaddr + "'...");
                            
                            try{
                                SendData(appSock, "255.255.255.255", 68, o.toBytes());
                            }catch(CommunicationException e){
                                throw new TransportLayerException(e.toString());
                            }
                        }else{
                            protInfo = new LayerInfo(getClass().getName());
                            protInfo.setObjectName(mParentStack.getParentNodeName());
                            protInfo.setDataType("DHCP Server");
                            protInfo.setLayer("Application ");
                            protInfo.setDescription("Recieved DHCP packet with invalid xid=" + p.xid + ".");
                            Simulation.addLayerInfo(protInfo);
                        }
                    }
                    /*if(!findLease()){
                     
                     }else{
                     }*/
                    break;
            }
        }else{
            // drop it;
            LayerInfo protInfo = new LayerInfo(getClass().getName());
            protInfo.setObjectName(mParentStack.getParentNodeName());
            protInfo.setDataType("DHCP Server");
            protInfo.setLayer("Application ");
            protInfo.setDescription("Recieved DHCP packet with invalid data.");
            Simulation.addLayerInfo(protInfo);
        }
    }