本文整理汇总了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();
}
}
示例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();
}
}