本文整理汇总了Java中org.projectfloodlight.openflow.protocol.OFMessage类的典型用法代码示例。如果您正苦于以下问题:Java OFMessage类的具体用法?Java OFMessage怎么用?Java OFMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OFMessage类属于org.projectfloodlight.openflow.protocol包,在下文中一共展示了OFMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verifyExceptionCaptured
import org.projectfloodlight.openflow.protocol.OFMessage; //导入依赖的package包/类
/**
* Verify that the given exception event capture (as returned by
* getAndInitExceptionCapture) has thrown an exception of the given
* expectedExceptionClass.
* Resets the capture
* @param err
*/
void verifyExceptionCaptured(
OFMessage err, Class<? extends Throwable> expectedExceptionClass) {
Throwable caughtEx = null;
// This should purposely cause an exception
try{
switchHandler.processOFMessage(err);
}
catch(Exception e){
// Capture the exception
caughtEx = e;
}
assertThat(caughtEx, CoreMatchers.instanceOf(expectedExceptionClass));
}
示例2: dispatchMessage
import org.projectfloodlight.openflow.protocol.OFMessage; //导入依赖的package包/类
public void dispatchMessage(IOFSwitch sw, OFMessage msg, FloodlightContext bc) {
List<IOFMessageListener> theListeners = listeners.get(msg.getType()).getOrderedListeners();
if (theListeners != null) {
Command result = Command.CONTINUE;
Iterator<IOFMessageListener> it = theListeners.iterator();
if (OFType.PACKET_IN.equals(msg.getType())) {
OFPacketIn pi = (OFPacketIn)msg;
Ethernet eth = new Ethernet();
eth.deserialize(pi.getData(), 0, pi.getData().length);
IFloodlightProviderService.bcStore.put(bc,
IFloodlightProviderService.CONTEXT_PI_PAYLOAD,
eth);
}
while (it.hasNext() && !Command.STOP.equals(result)) {
result = it.next().receive(sw, msg, bc);
}
}
}
示例3: sendHandshakeSetConfig
import org.projectfloodlight.openflow.protocol.OFMessage; //导入依赖的package包/类
/**
* Send the configuration requests to tell the switch we want full
* packets
* @throws IOException
*/
private void sendHandshakeSetConfig() {
// Ensure we receive the full packet via PacketIn
// FIXME: We don't set the reassembly flags.
OFSetConfig configSet = factory.buildSetConfig()
.setXid(handshakeTransactionIds--)
.setMissSendLen(0xffff)
.build();
// Barrier
OFBarrierRequest barrier = factory.buildBarrierRequest()
.setXid(handshakeTransactionIds--)
.build();
// Verify (need barrier?)
OFGetConfigRequest configReq = factory.buildGetConfigRequest()
.setXid(handshakeTransactionIds--)
.build();
List<OFMessage> msgList = ImmutableList.<OFMessage>of(configSet, barrier, configReq);
mainConnection.write(msgList);
}
示例4: receive
import org.projectfloodlight.openflow.protocol.OFMessage; //导入依赖的package包/类
@Override
public net.floodlightcontroller.core.IListener.Command receive(
IOFSwitch sw, OFMessage msg, FloodlightContext cntx) {
System.out.println("flow expired: "+sw.toString() + msg.toString());
//OFFlowRemoved flowRemoved = (OFFlowRemoved) msg;
if (!switchStates.containsKey(sw))
switchStates.put(sw, new ObfuscationSwitchState(sw));
if (msg.getType() == OFType.FLOW_REMOVED) {
OFFlowRemoved flowRemoved = (OFFlowRemoved) msg;
System.out.println("flow expired: "+sw.toString() + "dst: " + flowRemoved.getCookie());
long dst = flowRemoved.getCookie().getValue();
ObfuscationHeader oHeader = new ObfuscationHeader();
Match match = flowRemoved.getMatch();
switchStates.get(sw).removeDestinationID(dst);
}
return Command.CONTINUE;
}
示例5: createHubPacketOut
import org.projectfloodlight.openflow.protocol.OFMessage; //导入依赖的package包/类
private OFMessage createHubPacketOut(IOFSwitch sw, OFMessage msg) {
OFPacketIn pi = (OFPacketIn) msg;
OFPacketOut.Builder pob = sw.getOFFactory().buildPacketOut();
pob.setBufferId(pi.getBufferId()).setXid(pi.getXid()).setInPort((pi.getVersion().compareTo(OFVersion.OF_12) < 0 ? pi.getInPort() : pi.getMatch().get(MatchField.IN_PORT)));
// set actions
OFActionOutput.Builder actionBuilder = sw.getOFFactory().actions().buildOutput();
actionBuilder.setPort(OFPort.FLOOD);
pob.setActions(Collections.singletonList((OFAction) actionBuilder.build()));
// set data if it is included in the packetin
if (pi.getBufferId() == OFBufferId.NO_BUFFER) {
byte[] packetData = pi.getData();
pob.setData(packetData);
}
return pob.build();
}
示例6: moveToWaitHello
import org.projectfloodlight.openflow.protocol.OFMessage; //导入依赖的package包/类
@Test
public void moveToWaitHello() throws Exception {
resetChannel();
channel.write(capture(writeCapture));
expectLastCall().andReturn(null).once();
replay(channel);
// replay unused mocks
replay(messageEvent);
handler.channelConnected(ctx, channelStateEvent);
List<OFMessage> msgs = getMessagesFromCapture();
assertEquals(1, msgs.size());
assertEquals(OFType.HELLO, msgs.get(0).getType());
assertThat(handler.getStateForTesting(), CoreMatchers.instanceOf(OFChannelHandler.WaitHelloState.class));
verifyUniqueXids(msgs);
}
示例7: handleOutgoingMessage
import org.projectfloodlight.openflow.protocol.OFMessage; //导入依赖的package包/类
@Override
public void handleOutgoingMessage(IOFSwitch sw, OFMessage m) {
FloodlightContext bc = new FloodlightContext();
List<IOFMessageListener> msgListeners = null;
if (listeners.containsKey(m.getType())) {
msgListeners = listeners.get(m.getType()).getOrderedListeners();
}
if (msgListeners != null) {
for (IOFMessageListener listener : msgListeners) {
if (Command.STOP.equals(listener.receive(sw, m, bc))) {
break;
}
}
}
}
示例8: doWrite
import org.projectfloodlight.openflow.protocol.OFMessage; //导入依赖的package包/类
protected void doWrite(boolean expectWrite,
OFMessageDamperMockSwitch sw,
OFMessage msg) throws IOException {
boolean result;
sw.reset();
result = damper.write(sw, msg);
if (expectWrite) {
assertEquals(true, result);
sw.assertMessageWasWritten(msg);
} else {
assertEquals(false, result);
sw.assertNoMessageWritten();
}
}
示例9: moveToWaitFeaturesReply
import org.projectfloodlight.openflow.protocol.OFMessage; //导入依赖的package包/类
/** Move the channel from scratch to WAIT_FEATURES_REPLY state
* Builds on moveToWaitHello()
* adds testing for WAIT_HELLO state
*/
@Test
public void moveToWaitFeaturesReply() throws Exception {
moveToWaitHello();
resetChannel();
expect(channel.writeAndFlush(capture(writeCapture))).andReturn(null).atLeastOnce();
replay(channel);
OFMessage hello = factory.buildHello().build();
sendMessageToHandlerWithControllerReset(ImmutableList.<OFMessage>of(hello));
List<OFMessage> msgs = getMessagesFromCapture();
assertEquals(1, msgs.size());
assertEquals(OFType.FEATURES_REQUEST, msgs.get(0).getType());
verifyUniqueXids(msgs);
assertThat(handler.getStateForTesting(), CoreMatchers.instanceOf(OFChannelHandler.WaitFeaturesReplyState.class));
}
示例10: encode
import org.projectfloodlight.openflow.protocol.OFMessage; //导入依赖的package包/类
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel,
Object msg) throws Exception {
if (!(msg instanceof List)) {
return msg;
}
@SuppressWarnings("unchecked")
List<OFMessage> msglist = (List<OFMessage>) msg;
/* XXX S can't get length of OFMessage in loxigen's openflowj??
int size = 0;
for (OFMessage ofm : msglist) {
size += ofm.getLengthU();
}*/
ChannelBuffer buf = ChannelBuffers.dynamicBuffer();
for (OFMessage ofm : msglist) {
if (ofm != null) {
ofm.writeTo(buf);
}
}
return buf;
}
示例11: messageReceived
import org.projectfloodlight.openflow.protocol.OFMessage; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e)
throws Exception {
if (e.getMessage() instanceof List) {
@SuppressWarnings("unchecked")
List<OFMessage> msglist = (List<OFMessage>) e.getMessage();
for (OFMessage ofm : msglist) {
// Do the actual packet processing
state.processOFMessage(this, ofm);
}
} else {
state.processOFMessage(this, (OFMessage) e.getMessage());
}
}
示例12: handleOutgoingMessage
import org.projectfloodlight.openflow.protocol.OFMessage; //导入依赖的package包/类
@Override
public void handleOutgoingMessage(IOFSwitch sw, OFMessage m) {
if (sw == null)
throw new NullPointerException("Switch must not be null");
if (m == null)
throw new NullPointerException("OFMessage must not be null");
// FIXME floodlight context not supported any more
FloodlightContext bc = new FloodlightContext();
List<IOFMessageListener> listeners = null;
if (messageListeners.containsKey(m.getType())) {
listeners = messageListeners.get(m.getType()).getOrderedListeners();
}
if (listeners != null) {
for (IOFMessageListener listener : listeners) {
if (Command.STOP.equals(listener.receive(sw, m, bc))) {
break;
}
}
}
}
示例13: testSingleMessageWrite
import org.projectfloodlight.openflow.protocol.OFMessage; //导入依赖的package包/类
/** write a packetOut, which is buffered */
@Test(timeout = 5000)
public void testSingleMessageWrite() throws InterruptedException, ExecutionException {
Capture<List<OFMessage>> cMsgList = prepareChannelForWriteList();
OFPacketOut packetOut = factory.buildPacketOut()
.setData(new byte[] { 0x01, 0x02, 0x03, 0x04 })
.setActions(ImmutableList.<OFAction>of( factory.actions().output(OFPort.of(1), 0)))
.build();
conn.write(packetOut);
assertThat("Write should have been flushed", cMsgList.hasCaptured(), equalTo(true));
List<OFMessage> value = cMsgList.getValue();
logger.info("Captured channel write: "+value);
assertThat("Should have captured MsgList", cMsgList.getValue(),
Matchers.<OFMessage> contains(packetOut));
}
示例14: moveToWaitFeaturesReply
import org.projectfloodlight.openflow.protocol.OFMessage; //导入依赖的package包/类
/** Move the channel from scratch to WAIT_FEATURES_REPLY state
* Builds on moveToWaitHello()
* adds testing for WAIT_HELLO state
*/
@Test
public void moveToWaitFeaturesReply() throws Exception {
moveToWaitHello();
resetChannel();
channel.write(capture(writeCapture));
expectLastCall().andReturn(null).atLeastOnce();
replay(channel);
OFMessage hello = factory.buildHello().build();
sendMessageToHandlerWithControllerReset(ImmutableList.<OFMessage>of(hello));
List<OFMessage> msgs = getMessagesFromCapture();
assertEquals(1, msgs.size());
assertEquals(OFType.FEATURES_REQUEST, msgs.get(0).getType());
verifyUniqueXids(msgs);
assertThat(handler.getStateForTesting(), CoreMatchers.instanceOf(OFChannelHandler.WaitFeaturesReplyState.class));
}
示例15: handleGenericDeliverable
import org.projectfloodlight.openflow.protocol.OFMessage; //导入依赖的package包/类
public boolean handleGenericDeliverable(OFMessage reply) {
counters.updateReadStats(reply);
@SuppressWarnings("unchecked")
Deliverable<OFMessage> deliverable =
(Deliverable<OFMessage>) this.xidDeliverableMap.get(reply.getXid());
if (deliverable != null) {
if(reply instanceof OFErrorMsg) {
deliverable.deliverError(new OFErrorMsgException((OFErrorMsg) reply));
} else {
deliverable.deliver(reply);
}
if (deliverable.isDone())
this.xidDeliverableMap.remove(reply.getXid());
return true;
} else {
return false;
}
}