首页 > 代码库 > 从PACKET_IN消息中得到packet data

从PACKET_IN消息中得到packet data


     在Floodlight模块中如果想得到packet in消息,就对相应的消息类型进行监听即可,然后在receive方法中就可以操纵这个上传上来的packet_in。
     关键代码:
 
    Ethernet eth = IFloodlightProviderService.bcStore.get(cntx,
                                            IFloodlightProviderService.CONTEXT_PI_PAYLOAD);
          
          if(eth.getEtherType() == Ethernet.TYPE_IPv4){
                IPv4 ipPkt = (IPv4)eth.getPayload();
                if(ipPkt.getProtocol() == IPv4.PROTOCOL_UDP){
                         UDP udpPkt = (UDP)ipPkt.getPayload();
                         Data dataPkt = (Data)udpPkt.getPayload();
               
                        System.out.println(dataPkt.getData().length);  
                        
                        byte[] arr = dataPkt.getData();
                        for (int i = 0; i < dataPkt.getData().length; i++){
                                  System.out.print((char)arr[i]);
                        }
                 }
          }