当前位置: 首页>>代码示例>>Java>>正文


Java Packet类代码示例

本文整理汇总了Java中org.opendaylight.controller.sal.packet.Packet的典型用法代码示例。如果您正苦于以下问题:Java Packet类的具体用法?Java Packet怎么用?Java Packet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Packet类属于org.opendaylight.controller.sal.packet包,在下文中一共展示了Packet类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: receiveDataPacket

import org.opendaylight.controller.sal.packet.Packet; //导入依赖的package包/类
@Override
public PacketResult receiveDataPacket(RawPacket inPkt) {
    if (inPkt == null) {
        return PacketResult.IGNORED;
    }
    logger.trace("Received a frame of size: {}",
                    inPkt.getPacketData().length);
    Packet formattedPak = this.dataPacketService.decodeDataPacket(inPkt);
    if (formattedPak instanceof Ethernet) {
        Object nextPak = formattedPak.getPayload();
        if (nextPak instanceof IPv4) {
            handlePuntedIPPacket((IPv4) nextPak, inPkt
                    .getIncomingNodeConnector());
            logger.trace("Handled IP packet");
        }
        if (nextPak instanceof ARP) {
            handleARPPacket((Ethernet) formattedPak, (ARP) nextPak, inPkt
                    .getIncomingNodeConnector());
            logger.trace("Handled ARP packet");
        }
    }
    return PacketResult.IGNORED;
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:24,代码来源:ArpHandler.java

示例2: decodeDataPacket

import org.opendaylight.controller.sal.packet.Packet; //导入依赖的package包/类
@Override
public Packet decodeDataPacket(RawPacket pkt) {
    // Sanity checks
    if (pkt == null) {
        return null;
    }
    byte[] data = pkt.getPacketData();
    if (data.length <= 0) {
        return null;
    }
    if (pkt.getEncap().equals(LinkEncap.ETHERNET)) {
        Ethernet res = new Ethernet();
        try {
            res.deserialize(data, 0, data.length * NetUtils.NumBitsInAByte);
        } catch (Exception e) {
            logger.warn("Failed to decode packet: {}", e.getMessage());
        }
        return res;
    }
    return null;
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:22,代码来源:DataPacketService.java

示例3: encodeDataPacket

import org.opendaylight.controller.sal.packet.Packet; //导入依赖的package包/类
@Override
public RawPacket encodeDataPacket(Packet pkt) {
    // Sanity checks
    if (pkt == null) {
        return null;
    }
    byte[] data;
    try {
        data = pkt.serialize();
    } catch (Exception e) {
        logger.error("",e);
        return null;
    }
    if (data.length <= 0) {
        return null;
    }
    try {
        RawPacket res = new RawPacket(data);
        return res;
    } catch (ConstructionException cex) {
    }
    // If something goes wrong then we have to return null
    return null;
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:25,代码来源:DataPacketService.java

示例4: pktToJSON

import org.opendaylight.controller.sal.packet.Packet; //导入依赖的package包/类
/**
 * Converts a packet to JSON representation.
 * 
 * @param pkt the packet to be converted
 * @return JSON representation.
 */
private JSONObject pktToJSON(RawPacket rawPkt) {
    log.trace("Received packet-in event.");
    
    JSONObject json = new JSONObject();
    
    // Add incoming node
    
    // The connector, the packet came from ("port")
    NodeConnector ingressConnector = rawPkt.getIncomingNodeConnector();
    // The node that received the packet ("switch")
    Node node = ingressConnector.getNode();

    JSONObject nodeJson = new JSONObject();
    nodeJson.put(NodeAttributes.Keys.ID.toJSON(), node.getNodeIDString());
    nodeJson.put(NodeAttributes.Keys.TYPE.toJSON(), node.getType());
    json.put(PacketInAttributes.Keys.NODE.toJSON(), nodeJson);
    
    // Add inport
    
    json.put(PacketInAttributes.Keys.INGRESS_PORT.toJSON(), ingressConnector.getNodeConnectorIDString());
    
    // Add raw packet data
    
    // Use DataPacketService to decode the packet.
    Packet pkt = dataPacketService.decodeDataPacket(rawPkt);

    while (pkt != null) {
        if (pkt instanceof Ethernet) {
            Ethernet ethernet = (Ethernet) pkt;
            ethernetToJSON(ethernet, json);
        } else if(pkt instanceof IEEE8021Q) {
            IEEE8021Q ieee802q = (IEEE8021Q) pkt;
            ieee8021qToJSON(ieee802q, json);
        } else if (pkt instanceof IPv4) {
            IPv4 ipv4 = (IPv4) pkt;
            ipv4ToJSON(ipv4, json);
        } else if (pkt instanceof TCP) {
            TCP tcp = (TCP) pkt;
            tcpToJSON(tcp, json);
        } else if (pkt instanceof UDP) {
            UDP udp = (UDP) pkt;
            udpToJSON(udp, json);
        }
        
        pkt = pkt.getPayload();
    }
    
    json.put(PacketInAttributes.Keys.PACKET.toJSON(), DatatypeConverter.printBase64Binary(rawPkt.getPacketData()));
    
    return json;
}
 
开发者ID:duerrfk,项目名称:sdn-mq,代码行数:58,代码来源:PacketHandler.java

示例5: getClientFromPacket

import org.opendaylight.controller.sal.packet.Packet; //导入依赖的package包/类
/**
 * Extract the details of the source machine that sent this packet 'inPkt'
 * @param inPkt Packet that is received by the controller
 * @return  Details of the source machine in Client object.
 */
public Client getClientFromPacket(IPv4 inPkt){
    lbuLogger.info("Find client information from packet : {}",inPkt.toString());

    String ip = NetUtils.getInetAddress(inPkt.getSourceAddress()).getHostAddress();

    String protocol = IPProtocols.getProtocolName(inPkt.getProtocol());

    lbuLogger.info("client ip {} and protocl {}",ip,protocol);

    Packet tpFrame= inPkt.getPayload();

    lbuLogger.info("Get protocol layer {}",tpFrame.toString());

    short port = 0;

    if(protocol.equals(IPProtocols.TCP.toString())){
        TCP tcpFrame = (TCP)tpFrame;
        port = tcpFrame.getSourcePort();
    }else{
        UDP udpFrame = (UDP)tpFrame;
        port = udpFrame.getSourcePort();
    }

    lbuLogger.info("Found port {}",port);

    Client source = new Client(ip, protocol,port);

    lbuLogger.info("Client information : {}",source.toString());

    return source;
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:37,代码来源:LBUtil.java

示例6: getVIPFromPacket

import org.opendaylight.controller.sal.packet.Packet; //导入依赖的package包/类
/**
 * Extract the details of the destination machine where this packet 'inPkt' need
 * to be delivered
 * @param inPkt Packet that is received by controller for forwarding
 * @return  Details of the destination machine packet in VIP
 */
public VIP getVIPFromPacket(IPv4 inPkt){

    lbuLogger.info("Find VIP information from packet : {}",inPkt.toString());

    String ip = NetUtils.getInetAddress(inPkt.getDestinationAddress()).getHostAddress();

    String protocol = IPProtocols.getProtocolName(inPkt.getProtocol());

    Packet tpFrame= inPkt.getPayload();

    short port = 0;

    if(protocol.equals(IPProtocols.TCP.toString())){
        TCP tcpFrame = (TCP)tpFrame;
        port = tcpFrame.getDestinationPort();
    }else{

        UDP udpFrame = (UDP)tpFrame;
        port = udpFrame.getDestinationPort();
    }

    VIP dest = new VIP(null,ip, protocol,port,null);

    lbuLogger.info("VIP information : {}",dest.toString());

    return dest;
}
 
开发者ID:lbchen,项目名称:ODL,代码行数:34,代码来源:LBUtil.java


注:本文中的org.opendaylight.controller.sal.packet.Packet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。