本文整理汇总了Java中org.projectfloodlight.openflow.exceptions.OFParseError类的典型用法代码示例。如果您正苦于以下问题:Java OFParseError类的具体用法?Java OFParseError怎么用?Java OFParseError使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OFParseError类属于org.projectfloodlight.openflow.exceptions包,在下文中一共展示了OFParseError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readList
import org.projectfloodlight.openflow.exceptions.OFParseError; //导入依赖的package包/类
public static <T> List<T> readList(ChannelBuffer bb, int length, OFMessageReader<T> reader) throws OFParseError {
int end = bb.readerIndex() + length;
Builder<T> builder = ImmutableList.<T>builder();
if(logger.isTraceEnabled())
logger.trace("readList(length={}, reader={})", length, reader.getClass());
while(bb.readerIndex() < end) {
T read = reader.readFrom(bb);
if(logger.isTraceEnabled())
logger.trace("readList: read={}, left={}", read, end - bb.readerIndex());
builder.add(read);
}
if(bb.readerIndex() != end) {
throw new IllegalStateException("Overread length: length="+length + " overread by "+ (bb.readerIndex() - end) + " reader: "+reader);
}
return builder.build();
}
示例2: readList
import org.projectfloodlight.openflow.exceptions.OFParseError; //导入依赖的package包/类
public static <T> List<T> readList(ByteBuf bb, int length, OFMessageReader<T> reader) throws OFParseError {
int end = bb.readerIndex() + length;
Builder<T> builder = ImmutableList.<T>builder();
if(logger.isTraceEnabled())
logger.trace("readList(length={}, reader={})", length, reader.getClass());
while(bb.readerIndex() < end) {
T read = reader.readFrom(bb);
if(logger.isTraceEnabled())
logger.trace("readList: read={}, left={}", read, end - bb.readerIndex());
builder.add(read);
}
if(bb.readerIndex() != end) {
throw new IllegalStateException("Overread length: length="+length + " overread by "+ (bb.readerIndex() - end) + " reader: "+reader);
}
return builder.build();
}
示例3: getParsedMessage
import org.projectfloodlight.openflow.exceptions.OFParseError; //导入依赖的package包/类
public Optional<OFMessage> getParsedMessage() {
OFFactory factory = OFFactories.getFactory(version);
try {
OFMessage msg = factory.getReader().readFrom(ChannelBuffers.wrappedBuffer(data));
if(msg != null)
return Optional.of(msg);
else
return Optional.absent();
} catch (OFParseError e) {
logger.debug("Error parsing error cause data as OFMessage: {}", e.getMessage(), e);
return Optional.absent();
}
}
示例4: ConcretizeMessage
import org.projectfloodlight.openflow.exceptions.OFParseError; //导入依赖的package包/类
/**
* Concretizes the given message to the corresponding convenience class.
*
* @param message
* the message
* @return the concretized message (e.g. an instance of OpenFlowMessage)
*/
public static Message ConcretizeMessage(Message message) {
try {
switch (message.getHeader().getMessageType()) {
case HELLO:
return toHelloMessage(message);
case ERROR:
return toErrorMessage(message);
case OPENFLOW:
return toOpenFlowMessage(message);
case NETCONF:
return toNetconfMessage(message);
case OPFLEX:
return toOpFlexMessage(message);
case MANAGEMENT:
return toManagementMessage(message);
case MODULE_ANNOUNCEMENT:
return toModuleAnnouncementMessage(message);
case MODULE_ACKNOWLEDGE:
return toModuleAcknowledgeMessage(message);
case TOPOLOGY_UPDATE:
return toTopologyUpdateMessage(message);
case FENCE:
return toFenceMessage(message);
case HEARTBEAT:
return toHeartbeatMessage(message);
default:
throw new IllegalArgumentException("Unknown message type.");
}
} catch (OFParseError ofpe) {
throw new IllegalArgumentException("Could not decode OpenFlow message.", ofpe);
}
}
示例5: toOpenFlowMessage
import org.projectfloodlight.openflow.exceptions.OFParseError; //导入依赖的package包/类
/**
* To open flow message.
*
* @param message
* the message
* @return the open flow message
* @throws OFParseError
* the oF parse error
*/
private static OpenFlowMessage toOpenFlowMessage(Message message) throws OFParseError {
if (message.getHeader().getMessageType() != MessageType.OPENFLOW)
throw new IllegalArgumentException("Can only convert OPENFLOW messages");
if (message instanceof OpenFlowMessage)
return (OpenFlowMessage) message;
OpenFlowMessage ofm = new OpenFlowMessage();
ofm.setHeader(message.getHeader());
ofm.setOfMessage(OFFactories.getGenericReader()
.readFrom(new ByteBufferBackedChannelBuffer(ByteBuffer.wrap(message.payload))));
return ofm;
}
示例6: messageReceived
import org.projectfloodlight.openflow.exceptions.OFParseError; //导入依赖的package包/类
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
ChannelBuffer buf = (ChannelBuffer) e.getMessage();
try {
OFMessage msg = OFFactories.getGenericReader().readFrom(buf);
handleMessage(msg);
} catch (OFParseError e1) {
logger.error(e1.getMessage());
} catch (IllegalArgumentException e2) {
logger.error(e2.getMessage());
}
}
示例7: decode
import org.projectfloodlight.openflow.exceptions.OFParseError; //导入依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel,
ChannelBuffer buffer) throws Exception {
if (!channel.isConnected()) {
// In testing, I see decode being called AFTER decode last.
// This check avoids that from reading corrupted frames
return null;
}
// Note that a single call to decode results in reading a single
// OFMessage from the channel buffer, which is passed on to, and processed
// by, the controller (in OFChannelHandler).
// This is different from earlier behavior (with the original openflowj),
// where we parsed all the messages in the buffer, before passing on
// a list of the parsed messages to the controller.
// The performance *may or may not* not be as good as before.
OFMessageReader<OFMessage> reader = OFFactories.getGenericReader();
OFMessage message = null;
try {
message = reader.readFrom(buffer);
} catch (OFParseError e) {
OFChannelHandler ofch = (OFChannelHandler) ctx.getPipeline().getLast();
log.error("Parse failure of incoming message from switch "
+ ofch.getChannelSwitchInfo() + " Index:Byte ==> {}:{} {}",
buffer.readerIndex(),
buffer.getByte(buffer.readerIndex()),
buffer.array());
buffer.clear(); // MUST CLEAR BUFFER or next message will be read
// incorrectly
return null;
}
return message;
}
示例8: getParsedMessage
import org.projectfloodlight.openflow.exceptions.OFParseError; //导入依赖的package包/类
public Optional<OFMessage> getParsedMessage() {
OFFactory factory = OFFactories.getFactory(version);
try {
OFMessage msg = factory.getReader().readFrom(Unpooled.wrappedBuffer(data));
if(msg != null)
return Optional.of(msg);
else
return Optional.absent();
} catch (OFParseError e) {
logger.debug("Error parsing error cause data as OFMessage: {}", e.getMessage(), e);
return Optional.absent();
}
}
示例9: testReadFrom
import org.projectfloodlight.openflow.exceptions.OFParseError; //导入依赖的package包/类
@Test
public void testReadFrom() throws OFParseError, UnknownHostException {
for(int i=0; i < testStrings.length; i++ ) {
byte[] bytes = Inet6Address.getByName(testStrings[i]).getAddress();
IPv6Address ip = IPv6Address.read16Bytes(Unpooled.copiedBuffer(bytes));
assertEquals(testStrings[i], ip.toString());
assertArrayEquals(bytes, ip.getBytes());
}
}
示例10: testInvalidIPs
import org.projectfloodlight.openflow.exceptions.OFParseError; //导入依赖的package包/类
@Test
public void testInvalidIPs() throws OFParseError {
for(String invalid : invalidIPs) {
try {
IPv6Address.of(invalid);
fail("Invalid IP "+invalid+ " should have raised IllegalArgumentException");
} catch(IllegalArgumentException e) {
// ok
}
}
}
示例11: testZeroCompression
import org.projectfloodlight.openflow.exceptions.OFParseError; //导入依赖的package包/类
@Test
public void testZeroCompression() throws OFParseError {
assertEquals("::", IPv6Address.of("::").toString(true, false));
assertEquals("0:0:0:0:0:0:0:0", IPv6Address.of("::").toString(false, false));
assertEquals("0000:0000:0000:0000:0000:0000:0000:0000", IPv6Address.of("::").toString(false, true));
assertEquals("1::4:5:6:0:8", IPv6Address.of("1:0:0:4:5:6:0:8").toString(true, false));
assertEquals("1:0:0:4::8", IPv6Address.of("1:0:0:4:0:0:0:8").toString(true, false));
// Two equal length zero runs; should zero compress the first instance
assertEquals("1::4:2:0:0:8", IPv6Address.of("1:0:0:4:2:0:0:8").toString(true, false));
// Shouldn't zero compress a single zero
assertEquals("1:0:2:4:3:1:0:8", IPv6Address.of("1:0:2:4:3:1:0:8").toString(true, false));
// Test zero runs at the end of the address since that's a different code path in toString
assertEquals("1::4:2:8:0:0", IPv6Address.of("1:0:0:4:2:8:0:0").toString(true, false));
assertEquals("1:3:2:4:3:1:5:0", IPv6Address.of("1:3:2:4:3:1:5:0").toString(true, false));
}
示例12: testReadFrom
import org.projectfloodlight.openflow.exceptions.OFParseError; //导入依赖的package包/类
@Test
public void testReadFrom() throws OFParseError {
for(int i=0; i < testAddresses.length; i++ ) {
IPv4Address ip = IPv4Address.read4Bytes(Unpooled.copiedBuffer(testAddresses[i]));
assertEquals(testInts[i], ip.getInt());
assertArrayEquals(testAddresses[i], ip.getBytes());
assertEquals(testStrings[i], ip.toString());
}
}
示例13: testInvalidIPs
import org.projectfloodlight.openflow.exceptions.OFParseError; //导入依赖的package包/类
@Test
public void testInvalidIPs() throws OFParseError {
for(String invalid : invalidIPs) {
try {
IPv4Address.of(invalid);
fail("Invalid IP "+invalid+ " should have raised IllegalArgumentException");
} catch(IllegalArgumentException e) {
// ok
}
}
}
示例14: testOfMasked
import org.projectfloodlight.openflow.exceptions.OFParseError; //导入依赖的package包/类
@Test
public void testOfMasked() throws OFParseError {
for (int i = 0; i < ipsWithMask.length; i++) {
IPv4AddressWithMask value = IPv4AddressWithMask.of(ipsWithMask[i]);
if (!hasMask[i]) {
IPv4Address ip = value.getValue();
assertArrayEquals(ipsWithMaskValues[i][0], ip.getBytes());
}
IPv4Address mask = value.getMask();
if (ipsWithMaskLengths[i] == -1) {
assertFalse(mask.isCidrMask());
try {
mask.asCidrMaskLength();
fail("Expected IllegalStateException not thrown");
} catch(IllegalStateException e) {
//expected
}
} else {
assertTrue(mask.isCidrMask());
assertEquals(ipsWithMaskLengths[i], mask.asCidrMaskLength());
}
assertArrayEquals(ipsWithMaskValues[i][1], mask.getBytes());
byte[] ipBytes = new byte[4];
System.arraycopy(ipsWithMaskValues[i][0], 0, ipBytes, 0, 4);
assertEquals(ipBytes.length, value.getValue().getBytes().length);
for (int j = 0; j < ipBytes.length; j++) {
ipBytes[j] &= ipsWithMaskValues[i][1][j];
}
assertArrayEquals(ipBytes, value.getValue().getBytes());
assertThat(String.format("Byte comparison for mask of %s (%s)", ipsWithMask[i], value),
value.getMask().getBytes(), CoreMatchers.equalTo(ipsWithMaskValues[i][1]));
}
}
示例15: testReadFrom
import org.projectfloodlight.openflow.exceptions.OFParseError; //导入依赖的package包/类
@Test
public void testReadFrom() throws OFParseError {
for(int i=0; i < testAddresses.length; i++ ) {
MacAddress ip = MacAddress.read6Bytes(Unpooled.copiedBuffer(testAddresses[i]));
assertEquals(testInts[i], ip.getLong());
assertArrayEquals(testAddresses[i], ip.getBytes());
assertEquals(testColonStrings[i], ip.toString());
}
}