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


Java OFPacketOut.writeTo方法代码示例

本文整理汇总了Java中org.openflow.protocol.OFPacketOut.writeTo方法的典型用法代码示例。如果您正苦于以下问题:Java OFPacketOut.writeTo方法的具体用法?Java OFPacketOut.writeTo怎么用?Java OFPacketOut.writeTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openflow.protocol.OFPacketOut的用法示例。


在下文中一共展示了OFPacketOut.writeTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendPacket

import org.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
protected void sendPacket(HashSet<String> matchedFilters, IOFSwitch sw, 
        OFMessage msg, FloodlightContext cntx, boolean sync) 
                throws TException {
    Message sendMsg = new Message();
    Packet packet = new Packet();
    ChannelBuffer bb;
    sendMsg.setPacket(packet);

    List<String> sids = new ArrayList<String>(matchedFilters);

    sendMsg.setSessionIDs(sids);
    packet.setMessageType(OFMessageType.findByValue((msg.getType().ordinal())));

    switch (msg.getType()) {
        case PACKET_IN:
            OFPacketIn pktIn = (OFPacketIn)msg;
            packet.setSwPortTuple(new SwitchPortTuple(sw.getId(), 
                                                      pktIn.getInPort()));
            bb = ChannelBuffers.buffer(pktIn.getLength());
            pktIn.writeTo(bb);
            packet.setData(OFMessage.getData(sw, msg, cntx));
            break;
        case PACKET_OUT:
            OFPacketOut pktOut = (OFPacketOut)msg;
            packet.setSwPortTuple(new SwitchPortTuple(sw.getId(), 
                                                      pktOut.getInPort()));
            bb = ChannelBuffers.buffer(pktOut.getLength());
            pktOut.writeTo(bb);
            packet.setData(OFMessage.getData(sw, msg, cntx));
            break;
        case FLOW_MOD:
            OFFlowMod offlowMod = (OFFlowMod)msg;
            packet.setSwPortTuple(new SwitchPortTuple(sw.getId(), 
                                                      offlowMod.
                                                      getOutPort()));
            bb = ChannelBuffers.buffer(offlowMod.getLength());
            offlowMod.writeTo(bb);
            packet.setData(OFMessage.getData(sw, msg, cntx));
            break;
        default:
            packet.setSwPortTuple(new SwitchPortTuple(sw.getId(), 
                                                      (short)0));
            String strData = "Unknown packet";
            packet.setData(strData.getBytes());
            break;
    }

    try {
        if (transport == null || 
            !transport.isOpen() || 
            packetClient == null) {
            if (!connectToPSServer()) {
                // No need to sendPacket if can't make connection to 
                // the server
                return;
            }
        }
        if (sync) {
            log.debug("Send packet sync: {}", packet.toString());
            packetClient.pushMessageSync(sendMsg);
        } else {
            log.debug("Send packet sync: ", packet.toString());
            packetClient.pushMessageAsync(sendMsg);
        }
    } catch (Exception e) {
        log.error("Error while sending packet", e);
        disconnectFromPSServer();
        connectToPSServer();
    }
}
 
开发者ID:JianqingJiang,项目名称:QoS-floodlight,代码行数:71,代码来源:OFMessageFilterManager.java

示例2: sendPacket

import org.openflow.protocol.OFPacketOut; //导入方法依赖的package包/类
protected void sendPacket(HashSet<String> matchedFilters, IOFSwitch sw, 
        OFMessage msg, ListenerContext cntx, boolean sync) 
                throws TException {
    Message sendMsg = new Message();
    Packet packet = new Packet();
    ChannelBuffer bb;
    sendMsg.setPacket(packet);

    List<String> sids = new ArrayList<String>(matchedFilters);

    sendMsg.setSessionIDs(sids);
    packet.setMessageType(OFMessageType.findByValue((msg.getType().ordinal())));

    switch (msg.getType()) {
        case PACKET_IN:
            OFPacketIn pktIn = (OFPacketIn)msg;
            packet.setSwPortTuple(new SwitchPortTuple(sw.getId(), 
                                                      pktIn.getInPort()));
            bb = ChannelBuffers.buffer(pktIn.getLength());
            pktIn.writeTo(bb);
            packet.setData(OFMessage.getData(sw, msg, cntx));
            break;
        case PACKET_OUT:
            OFPacketOut pktOut = (OFPacketOut)msg;
            packet.setSwPortTuple(new SwitchPortTuple(sw.getId(), 
                                                      pktOut.getInPort()));
            bb = ChannelBuffers.buffer(pktOut.getLength());
            pktOut.writeTo(bb);
            packet.setData(OFMessage.getData(sw, msg, cntx));
            break;
        case FLOW_MOD:
            OFFlowMod offlowMod = (OFFlowMod)msg;
            packet.setSwPortTuple(new SwitchPortTuple(sw.getId(), 
                                                      offlowMod.
                                                      getOutPort()));
            bb = ChannelBuffers.buffer(offlowMod.getLength());
            offlowMod.writeTo(bb);
            packet.setData(OFMessage.getData(sw, msg, cntx));
            break;
        default:
            packet.setSwPortTuple(new SwitchPortTuple(sw.getId(), 
                                                      (short)0));
            String strData = "Unknown packet";
            packet.setData(strData.getBytes());
            break;
    }

    try {
        if (transport == null || 
            !transport.isOpen() || 
            packetClient == null) {
            if (!connectToPSServer()) {
                // No need to sendPacket if can't make connection to 
                // the server
                return;
            }
        }
        if (sync) {
            log.debug("Send packet sync: {}", packet.toString());
            packetClient.pushMessageSync(sendMsg);
        } else {
            log.debug("Send packet sync: ", packet.toString());
            packetClient.pushMessageAsync(sendMsg);
        }
    } catch (Exception e) {
        log.error("Error while sending packet", e);
        disconnectFromPSServer();
        connectToPSServer();
    }
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:71,代码来源:OFMessageFilterManager.java


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