本文整理汇总了Java中org.projectfloodlight.openflow.protocol.OFFactories类的典型用法代码示例。如果您正苦于以下问题:Java OFFactories类的具体用法?Java OFFactories怎么用?Java OFFactories使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OFFactories类属于org.projectfloodlight.openflow.protocol包,在下文中一共展示了OFFactories类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import org.projectfloodlight.openflow.protocol.OFFactories; //导入依赖的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 = reader.readFrom(buffer);
return message;
}
示例2: sendNxRoleRequest
import org.projectfloodlight.openflow.protocol.OFFactories; //导入依赖的package包/类
/**
* Send NX role request message to the switch requesting the specified
* role.
*
* @param role role to request
*/
private int sendNxRoleRequest(RoleState role) throws IOException {
// Convert the role enum to the appropriate role to send
OFNiciraControllerRole roleToSend = OFNiciraControllerRole.ROLE_OTHER;
switch (role) {
case MASTER:
roleToSend = OFNiciraControllerRole.ROLE_MASTER;
break;
case SLAVE:
case EQUAL:
default:
// ensuring that the only two roles sent to 1.0 switches with
// Nicira role support, are MASTER and SLAVE
roleToSend = OFNiciraControllerRole.ROLE_OTHER;
log.debug("Sending Nx Role.SLAVE to switch {}.", sw);
}
int xid = sw.getNextTransactionId();
OFExperimenter roleRequest = OFFactories.getFactory(OFVersion.OF_10)
.buildNiciraControllerRoleRequest()
.setXid(xid)
.setRole(roleToSend)
.build();
sw.sendRoleRequest(roleRequest);
return xid;
}
示例3: groupStatsEvent
import org.projectfloodlight.openflow.protocol.OFFactories; //导入依赖的package包/类
@Test
public void groupStatsEvent() {
TestOpenFlowGroupProviderService testProviderService =
(TestOpenFlowGroupProviderService) providerService;
OFGroupStatsReply.Builder rep1 =
OFFactories.getFactory(OFVersion.OF_13).buildGroupStatsReply();
rep1.setXid(1);
controller.processPacket(dpid1, rep1.build());
OFGroupDescStatsReply.Builder rep2 =
OFFactories.getFactory(OFVersion.OF_13).buildGroupDescStatsReply();
assertNull("group entries is not set yet", testProviderService.getGroupEntries());
rep2.setXid(2);
controller.processPacket(dpid1, rep2.build());
assertNotNull("group entries should be set", testProviderService.getGroupEntries());
}
示例4: decode_set_vlan_id
import org.projectfloodlight.openflow.protocol.OFFactories; //导入依赖的package包/类
/**
* Parse set_vlan_id actions.
* The key and delimiter for the action should be omitted, and only the
* data should be presented to this decoder. Data with a leading 0x is permitted.
*
* @param actionToDecode; The action as a string to decode
* @param version; The OF version to create the action for
* @param log
* @return
*/
private static OFActionSetVlanVid decode_set_vlan_id(String actionToDecode, OFVersion version, Logger log) {
Matcher n = Pattern.compile("((?:0x)?\\d+)").matcher(actionToDecode);
if (n.matches()) {
if (n.group(1) != null) {
try {
VlanVid vlanid = VlanVid.ofVlan(get_short(n.group(1)));
OFActionSetVlanVid.Builder ab = OFFactories.getFactory(version).actions().buildSetVlanVid();
ab.setVlanVid(vlanid);
log.debug("action {}", ab.build());
return ab.build();
}
catch (NumberFormatException e) {
log.debug("Invalid VLAN in: {} (error ignored)", actionToDecode);
return null;
}
}
}
else {
log.debug("Invalid action: '{}'", actionToDecode);
return null;
}
return null;
}
示例5: decode_set_vlan_priority
import org.projectfloodlight.openflow.protocol.OFFactories; //导入依赖的package包/类
/**
* Parse set_vlan_pcp actions.
* The key and delimiter for the action should be omitted, and only the
* data should be presented to this decoder. Data with a leading 0x is permitted.
*
* @param actionToDecode; The action as a string to decode
* @param version; The OF version to create the action for
* @param log
* @return
*/
private static OFActionSetVlanPcp decode_set_vlan_priority(String actionToDecode, OFVersion version, Logger log) {
Matcher n = Pattern.compile("((?:0x)?\\d+)").matcher(actionToDecode);
if (n.matches()) {
if (n.group(1) != null) {
try {
VlanPcp prior = VlanPcp.of(get_byte(n.group(1)));
OFActionSetVlanPcp.Builder ab = OFFactories.getFactory(version).actions().buildSetVlanPcp();
ab.setVlanPcp(prior);
log.debug("action {}", ab.build());
return ab.build();
}
catch (NumberFormatException e) {
log.debug("Invalid VLAN priority in: {} (error ignored)", actionToDecode);
return null;
}
}
}
else {
log.debug("Invalid action: '{}'", actionToDecode);
return null;
}
return null;
}
示例6: decode_set_src_mac
import org.projectfloodlight.openflow.protocol.OFFactories; //导入依赖的package包/类
/**
* Parse set_dl_src actions.
* The key and delimiter for the action should be omitted, and only the
* data should be presented to this decoder.
*
* TODO should consider using MacAddress's built-in parser....
*
* @param actionToDecode; The action as a string to decode
* @param version; The OF version to create the action for
* @param log
* @return
*/
private static OFActionSetDlSrc decode_set_src_mac(String actionToDecode, OFVersion version, Logger log) {
Matcher n = Pattern.compile("(?:(\\p{XDigit}+)\\:(\\p{XDigit}+)\\:(\\p{XDigit}+)\\:(\\p{XDigit}+)\\:(\\p{XDigit}+)\\:(\\p{XDigit}+))").matcher(actionToDecode);
if (n.matches()) {
MacAddress macaddr = MacAddress.of(get_mac_addr(n, actionToDecode, log));
if (macaddr != null) {
OFActionSetDlSrc.Builder ab = OFFactories.getFactory(version).actions().buildSetDlSrc();
ab.setDlAddr(macaddr);
log.debug("action {}", ab.build());
return ab.build();
}
}
else {
log.debug("Invalid action: '{}'", actionToDecode);
return null;
}
return null;
}
示例7: decode_set_dst_mac
import org.projectfloodlight.openflow.protocol.OFFactories; //导入依赖的package包/类
/**
* Parse set_dl_dst actions.
* The key and delimiter for the action should be omitted, and only the
* data should be presented to this decoder.
*
* TODO should consider using MacAddress's built-in parser....
*
* @param actionToDecode; The action as a string to decode
* @param version; The OF version to create the action for
* @param log
* @return
*/
private static OFActionSetDlDst decode_set_dst_mac(String actionToDecode, OFVersion version, Logger log) {
Matcher n = Pattern.compile("(?:(\\p{XDigit}+)\\:(\\p{XDigit}+)\\:(\\p{XDigit}+)\\:(\\p{XDigit}+)\\:(\\p{XDigit}+)\\:(\\p{XDigit}+))").matcher(actionToDecode);
if (n.matches()) {
MacAddress macaddr = MacAddress.of(get_mac_addr(n, actionToDecode, log));
if (macaddr != null) {
OFActionSetDlDst.Builder ab = OFFactories.getFactory(version).actions().buildSetDlDst();
ab.setDlAddr(macaddr);
log.debug("action {}", ab.build());
return ab.build();
}
}
else {
log.debug("Invalid action: '{}'", actionToDecode);
return null;
}
return null;
}
示例8: decode_set_tos_bits
import org.projectfloodlight.openflow.protocol.OFFactories; //导入依赖的package包/类
/**
* Parse set_tos actions.
* The key and delimiter for the action should be omitted, and only the
* data should be presented to this decoder. A leading 0x is permitted.
*
* @param actionToDecode; The action as a string to decode
* @param version; The OF version to create the action for
* @param log
* @return
*/
private static OFActionSetNwTos decode_set_tos_bits(String actionToDecode, OFVersion version, Logger log) {
Matcher n = Pattern.compile("((?:0x)?\\d+)").matcher(actionToDecode);
if (n.matches()) {
if (n.group(1) != null) {
try {
byte tosbits = get_byte(n.group(1));
OFActionSetNwTos.Builder ab = OFFactories.getFactory(version).actions().buildSetNwTos();
ab.setNwTos(tosbits);
log.debug("action {}", ab.build());
return ab.build();
}
catch (NumberFormatException e) {
log.debug("Invalid dst-port in: {} (error ignored)", actionToDecode);
return null;
}
}
}
else {
log.debug("Invalid action: '{}'", actionToDecode);
return null;
}
return null;
}
示例9: decode_set_src_port
import org.projectfloodlight.openflow.protocol.OFFactories; //导入依赖的package包/类
/**
* Parse set_tp_src actions.
* The key and delimiter for the action should be omitted, and only the
* data should be presented to this decoder. A leading 0x is permitted.
*
* @param actionToDecode; The action as a string to decode
* @param version; The OF version to create the action for
* @param log
* @return
*/
private static OFActionSetTpSrc decode_set_src_port(String actionToDecode, OFVersion version, Logger log) {
Matcher n = Pattern.compile("((?:0x)?\\d+)").matcher(actionToDecode);
if (n.matches()) {
if (n.group(1) != null) {
try {
TransportPort portnum = TransportPort.of(get_int(n.group(1)));
OFActionSetTpSrc.Builder ab = OFFactories.getFactory(version).actions().buildSetTpSrc();
ab.setTpPort(portnum);
log.debug("action {}", ab.build());
return ab.build();
}
catch (NumberFormatException e) {
log.debug("Invalid src-port in: {} (error ignored)", actionToDecode);
return null;
}
}
}
else {
log.debug("Invalid action: '{}'", actionToDecode);
return null;
}
return null;
}
示例10: decode_set_dst_port
import org.projectfloodlight.openflow.protocol.OFFactories; //导入依赖的package包/类
/**
* Parse set_tp_dst actions.
* The key and delimiter for the action should be omitted, and only the
* data should be presented to this decoder. A leading 0x is permitted.
*
* @param actionToDecode; The action as a string to decode
* @param version; The OF version to create the action for
* @param log
* @return
*/
private static OFAction decode_set_dst_port(String actionToDecode, OFVersion version, Logger log) {
Matcher n = Pattern.compile("((?:0x)?\\d+)").matcher(actionToDecode);
if (n.matches()) {
if (n.group(1) != null) {
try {
TransportPort portnum = TransportPort.of(get_int(n.group(1)));
OFActionSetTpDst.Builder ab = OFFactories.getFactory(version).actions().buildSetTpDst();
ab.setTpPort(portnum);
log.debug("action {}", ab.build());
return ab.build();
}
catch (NumberFormatException e) {
log.debug("Invalid dst-port in: {} (error ignored)", actionToDecode);
return null;
}
}
}
else {
log.debug("Invalid action: '{}'", actionToDecode);
return null;
}
return null;
}
示例11: gotoTableFromString
import org.projectfloodlight.openflow.protocol.OFFactories; //导入依赖的package包/类
/**
* Convert the string representation of an OFInstructionGotoTable to
* an OFInstructionGotoTable. The instruction will be set within the
* OFFlowMod.Builder provided. Notice nothing is returned, but the
* side effect is the addition of an instruction in the OFFlowMod.Builder.
* @param fmb; The FMB in which to append the new instruction
* @param instStr; The string to parse the instruction from
* @param log
*/
public static void gotoTableFromString(OFFlowMod.Builder fmb, String inst, Logger log) {
if (inst == null || inst.equals("")) {
return;
}
if (fmb.getVersion().compareTo(OFVersion.OF_11) < 0) {
log.error("Goto Table Instruction not supported in OpenFlow 1.0");
return;
}
OFInstructionGotoTable.Builder ib = OFFactories.getFactory(fmb.getVersion()).instructions().buildGotoTable();
// Get the table ID
if (inst.startsWith("0x")) {
ib.setTableId(TableId.of(Integer.parseInt(inst.replaceFirst("0x", ""), 16)));
} else {
ib.setTableId(TableId.of(Integer.parseInt(inst))).build();
}
log.debug("Appending GotoTable instruction: {}", ib.build());
appendInstruction(fmb, ib.build());
log.debug("All instructions after append: {}", fmb.getInstructions());
}
示例12: clearActionsFromString
import org.projectfloodlight.openflow.protocol.OFFactories; //导入依赖的package包/类
/**
* Convert the string representation of an OFInstructionClearActions to
* an OFInstructionClearActions. The instruction will be set within the
* OFFlowMod.Builder provided. Notice nothing is returned, but the
* side effect is the addition of an instruction in the OFFlowMod.Builder.
* @param fmb; The FMB in which to append the new instruction
* @param instStr; The string to parse the instruction from
* @param log
*/
public static void clearActionsFromString(OFFlowMod.Builder fmb, String inst, Logger log) {
if (fmb.getVersion().compareTo(OFVersion.OF_11) < 0) {
log.error("Clear Actions Instruction not supported in OpenFlow 1.0");
return;
}
if (inst != null && inst.trim().isEmpty()) { /* Allow the empty string, since this is what specifies clear (i.e. key clear does not have any defined values). */
OFInstructionClearActions i = OFFactories.getFactory(fmb.getVersion()).instructions().clearActions();
log.debug("Appending ClearActions instruction: {}", i);
appendInstruction(fmb, i);
log.debug("All instructions after append: {}", fmb.getInstructions());
} else {
log.error("Got non-empty or null string, but ClearActions should not have any String sub-fields: {}", inst);
}
}
示例13: createPacketIn
import org.projectfloodlight.openflow.protocol.OFFactories; //导入依赖的package包/类
private OFPacketIn createPacketIn(String srcMAC, String dstMAC,
String srcIp, String dstIp, short vlan) {
IPacket testPacket = new Ethernet()
.setDestinationMACAddress(dstMAC)
.setSourceMACAddress(srcMAC)
.setVlanID(vlan)
.setEtherType(EthType.IPv4)
.setPayload(
new IPv4()
.setTtl((byte) 128)
.setSourceAddress(srcIp)
.setDestinationAddress(dstIp)
.setPayload(new UDP()
.setSourcePort((short) 5000)
.setDestinationPort((short) 5001)
.setPayload(new Data(new byte[] {0x01}))));
byte[] testPacketSerialized = testPacket.serialize();
OFPacketIn pi;
// build out input packet
pi = OFFactories.getFactory(OFVersion.OF_13).buildPacketIn()
.setBufferId(OFBufferId.NO_BUFFER)
.setData(testPacketSerialized)
.setReason(OFPacketInReason.NO_MATCH)
.build();
return pi;
}
示例14: decode_set_dst_port
import org.projectfloodlight.openflow.protocol.OFFactories; //导入依赖的package包/类
/**
* Parse set_tp_dst actions.
* The key and delimiter for the action should be omitted, and only the
* data should be presented to this decoder. A leading 0x is permitted.
*
* @param actionToDecode; The action as a string to decode
* @param version; The OF version to create the action for
* @param log
* @return
*/
private static OFAction decode_set_dst_port(String actionToDecode, OFVersion version, Logger log) {
Matcher n = Pattern.compile("((?:0x)?\\d+)").matcher(actionToDecode);
if (n.matches()) {
if (n.group(1) != null) {
try {
TransportPort portnum = TransportPort.of(get_short(n.group(1)));
OFActionSetTpDst.Builder ab = OFFactories.getFactory(version).actions().buildSetTpDst();
ab.setTpPort(portnum);
log.debug("action {}", ab.build());
return ab.build();
}
catch (NumberFormatException e) {
log.debug("Invalid dst-port in: {} (error ignored)", actionToDecode);
return null;
}
}
}
else {
log.debug("Invalid action: '{}'", actionToDecode);
return null;
}
return null;
}
示例15: meterFromString
import org.projectfloodlight.openflow.protocol.OFFactories; //导入依赖的package包/类
/**
* Convert the string representation of an OFInstructionMeter to
* an OFInstructionMeter. The instruction will be set within the
* OFFlowMod.Builder provided. Notice nothing is returned, but the
* side effect is the addition of an instruction in the OFFlowMod.Builder.
* @param fmb; The FMB in which to append the new instruction
* @param instStr; The string to parse the instruction from
* @param log
*/
public static void meterFromString(OFFlowMod.Builder fmb, String inst, Logger log) {
if (inst == null || inst.isEmpty()) {
return;
}
if (fmb.getVersion().compareTo(OFVersion.OF_13) < 0) {
log.error("Goto Meter Instruction not supported in OpenFlow 1.0, 1.1, or 1.2");
return;
}
OFInstructionMeter.Builder ib = OFFactories.getFactory(fmb.getVersion()).instructions().buildMeter();
if (inst.startsWith("0x")) {
ib.setMeterId(Long.valueOf(inst.replaceFirst("0x", ""), 16));
} else {
ib.setMeterId(Long.valueOf(inst));
}
log.debug("Appending (Goto)Meter instruction: {}", ib.build());
appendInstruction(fmb, ib.build());
log.debug("All instructions after append: {}", fmb.getInstructions());
}