本文整理汇总了Java中org.openflow.protocol.OFFlowMod.setLengthU方法的典型用法代码示例。如果您正苦于以下问题:Java OFFlowMod.setLengthU方法的具体用法?Java OFFlowMod.setLengthU怎么用?Java OFFlowMod.setLengthU使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openflow.protocol.OFFlowMod
的用法示例。
在下文中一共展示了OFFlowMod.setLengthU方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deleteFlow
import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
private void deleteFlow(Long switchId, OFFlowStatisticsReply flowStat){
List<IOFSwitch> switches = this.getSwitches();
for(IOFSwitch sw : switches){
if(sw.getId() == switchId){
OFFlowMod flowMod = new OFFlowMod();
flowMod.setMatch(flowStat.getMatch().clone());
flowMod.setIdleTimeout(flowStat.getIdleTimeout());
flowMod.setHardTimeout(flowStat.getHardTimeout());
flowMod.setCookie(flowStat.getCookie());
flowMod.setPriority(flowStat.getPriority());
flowMod.setCommand(OFFlowMod.OFPFC_DELETE_STRICT);
flowMod.setLengthU(OFFlowMod.MINIMUM_LENGTH);
flowMod.setXid(sw.getNextTransactionId());
List<OFMessage> msgs = new ArrayList<OFMessage>();
msgs.add((OFMessage)flowMod);
try {
sw.write(msgs, null);
} catch (IOException e) {
log.error("Error attempting to send flow delete for flow that fits in NO flowspace");
e.printStackTrace();
}
}
}
}
示例2: init
import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Adds flow for given switch, outgoing port, and DC switch port. Constructs {@link OFMatch} and instructs switch
* to send all packets from the given interface to dcPort interface
* @param sw
* @param floodlightProvider
* @param cntx
* @param dcPort
* @param inetPort
*/
public static void init(IOFSwitch sw, IFloodlightProviderService floodlightProvider, FloodlightContext cntx, short dcPort, short inetPort) {
logger.debug("init(IOFSwitch,IFloodlightProviderService,FloodlightContext,short OFPacketIn) begin");
//floodlightProvider.addOFMessageListener(OFType.PACKET_IN, this);
OFFlowMod flowMod = (OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD);
// Create new match
OFMatch match = new OFMatch();
match.setInputPort(inetPort);
match.setWildcards(OFMatch.OFPFW_ALL & ~OFMatch.OFPFW_IN_PORT);
flowMod.setMatch(match);
flowMod.setCommand(OFFlowMod.OFPFC_ADD);
flowMod.setIdleTimeout((short) 0);
flowMod.setHardTimeout((short) 0);
flowMod.setPriority((short) 10);
flowMod.setBufferId(OFPacketOut.BUFFER_ID_NONE);
flowMod.setFlags((short) 1);
List<OFAction> actions = new ArrayList<>();
actions.add(new OFActionOutput().setPort(dcPort));
flowMod.setActions(actions);
flowMod.setLengthU(OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH);
logger.debug("Modyfing to rule {}", flowMod.toString());
try {
sw.write(flowMod, cntx);
sw.flush();
logger.debug(String.format("Added return rule from port %d to port %d (to switch %s)", inetPort, dcPort, sw.getStringId()));
} catch (IOException ex) {
logger.error(String.format("Error while adding return flow rule (in port %d, out port %d) to switch %s", inetPort, dcPort, sw.getStringId()), ex);
}
logger.debug("init(IOFSwitch,IFloodlightProviderService,FloodlightContext,short OFPacketIn) end");
}
示例3: mod
import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Modifies particular flow rule in the switch {@link IOFSwitch}
* @param sw
* @param floodlightProvider
* @param cntx
* @param dcIP
* @param dcMask
* @param outPort
*/
public static void mod(IOFSwitch sw, IFloodlightProviderService floodlightProvider, FloodlightContext cntx, String dcIP, int dcMask, short outPort) {
logger.debug("mod(IOFSwitch,IFloodlightProviderService,FloodlightContext,String,int,short) begin");
OFFlowMod flowMod = (OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD);
OFMatch mTo = new OFMatch();
String match = "dl_type=0x800,nw_dst=" + dcIP + "/" + Integer.toString(dcMask);
mTo.fromString(match);
flowMod.setMatch(mTo);
flowMod.setCommand(OFFlowMod.OFPFC_MODIFY_STRICT); //OFPFC_MODIFY
flowMod.setIdleTimeout((short) 0);
flowMod.setHardTimeout((short) 0);
flowMod.setPriority((short) 100);
flowMod.setBufferId(OFPacketOut.BUFFER_ID_NONE);
flowMod.setFlags((short) 1);
List<OFAction> actions = new ArrayList<>();
actions.add(new OFActionOutput().setPort(outPort));
flowMod.setActions(actions);
flowMod.setLengthU(OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH);
logger.debug("Modyfing to rule {}", flowMod.toString());
try {
sw.write(flowMod, cntx);
sw.flush();
logger.debug(String.format("Flow rule (out port %d) added to switch %s", outPort, sw.getStringId()));
} catch (IOException ex) {
logger.error(String.format("Error while modyfing flow rule (out port %d) to switch %s", outPort, sw.getStringId()), ex);
}
logger.debug("mod(IOFSwitch,IFloodlightProviderService,FloodlightContext,String,int,short) end");
}
示例4: addFlowOnSwitchLinkPorts
import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
private void addFlowOnSwitchLinkPorts(IOFSwitch sw, OFFlowMod fm ,
OFMatch match,
Short inport,
ArrayList<Short> outports,
FloodlightContext cntx){
// set the match.
int multicastAddr = match.getNetworkDestination();
match.setNetworkDestination(multicastAddr);
match.setWildcards(Wildcards.FULL.matchOn(Flag.IN_PORT).
matchOn(Flag.NW_DST));
fm.setMatch(match);
for(Short outport: outports){
fm.getActions().add(new OFActionOutput().
setPort(outport));
}
fm.getMatch().setInputPort(inport);
((OFPacketOut) fm.getActions()).setActionsLength(
(short) (OFActionOutput.MINIMUM_LENGTH *
outports.size()));
int length = OFFlowMod.MINIMUM_LENGTH+
((OFPacketOut)fm.getActions()).getActionsLength();
fm.setLengthU(length);
try {
counterStore.updatePktOutFMCounterStoreLocal(sw, fm);
if (log.isTraceEnabled()) {
log.trace("Pushing Multicast flowmod multicast switchDPID={} " +
"sw={} inPort={} actions={}",
new Object[] {sw.getId(),
sw,
fm.getMatch().getInputPort(),
fm.getActions() });
}
messageDamper.write(sw, fm, cntx);
} catch (IOException e) {
log.error("Failure writing flow mod", e);
}
}
示例5: removeFlows
import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
public void removeFlows(){
List<OFStatistics> results = this.parent.getSlicedFlowStats(mySwitch.getId(), this.mySlicer.getSliceName());
if(results == null){
log.debug("Slicing failed!");
return;
}
List<OFMessage> deletes = new ArrayList<OFMessage>();
for(OFStatistics stat : results){
OFFlowStatisticsReply flowStat = (OFFlowStatisticsReply) stat;
OFFlowMod flow = new OFFlowMod();
flow.setMatch(flowStat.getMatch());
flow.setActions(flowStat.getActions());
int length = 0;
for(OFAction act: flow.getActions()){
length += act.getLength();
}
flow.setLengthU(OFFlowMod.MINIMUM_LENGTH + length);
flow.setCommand(OFFlowMod.OFPFC_DELETE);
deletes.add(flow);
this.flowCount = this.flowCount - 1;
}
try {
this.mySwitch.write(deletes, null);
} catch (IOException e) {
e.printStackTrace();
}
}
示例6: parseActionString
import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Parses OFFlowMod actions from strings.
* @param flowMod The OFFlowMod to set the actions for
* @param actionstr The string containing all the actions
* @param log A logger to log for errors.
*/
public static void parseActionString(OFFlowMod flowMod, String actionstr, Logger log) {
List<OFAction> actions = new LinkedList<OFAction>();
int actionsLength = 0;
if (actionstr != null) {
actionstr = actionstr.toLowerCase();
for (String subaction : actionstr.split(",")) {
String action = subaction.split("[=:]")[0];
SubActionStruct subaction_struct = null;
if (action.equals("output")) {
subaction_struct = decode_output(subaction, log);
}
else if (action.equals("enqueue")) {
subaction_struct = decode_enqueue(subaction, log);
}
else if (action.equals("strip-vlan")) {
subaction_struct = decode_strip_vlan(subaction, log);
}
else if (action.equals("set-vlan-id")) {
subaction_struct = decode_set_vlan_id(subaction, log);
}
else if (action.equals("set-vlan-priority")) {
subaction_struct = decode_set_vlan_priority(subaction, log);
}
else if (action.equals("set-src-mac")) {
subaction_struct = decode_set_src_mac(subaction, log);
}
else if (action.equals("set-dst-mac")) {
subaction_struct = decode_set_dst_mac(subaction, log);
}
else if (action.equals("set-tos-bits")) {
subaction_struct = decode_set_tos_bits(subaction, log);
}
else if (action.equals("set-src-ip")) {
subaction_struct = decode_set_src_ip(subaction, log);
}
else if (action.equals("set-dst-ip")) {
subaction_struct = decode_set_dst_ip(subaction, log);
}
else if (action.equals("set-src-port")) {
subaction_struct = decode_set_src_port(subaction, log);
}
else if (action.equals("set-dst-port")) {
subaction_struct = decode_set_dst_port(subaction, log);
}
else {
log.error("Unexpected action '{}', '{}'", action, subaction);
}
if (subaction_struct != null) {
actions.add(subaction_struct.action);
actionsLength += subaction_struct.len;
}
}
}
log.debug("action {}", actions);
flowMod.setActions(actions);
flowMod.setLengthU(OFFlowMod.MINIMUM_LENGTH + actionsLength);
}
示例7: parseActionString
import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Parses OFFlowMod actions from strings.
* @param flowMod The OFFlowMod to set the actions for
* @param actionstr The string containing all the actions
* @param log A logger to log for errors.
*/
@LogMessageDoc(level="ERROR",
message="Unexpected action '{action}', '{subaction}'",
explanation="A static flow entry contained an invalid action",
recommendation=LogMessageDoc.REPORT_CONTROLLER_BUG)
public static void parseActionString(OFFlowMod flowMod, String actionstr, Logger log) {
List<OFAction> actions = new LinkedList<OFAction>();
int actionsLength = 0;
if (actionstr != null) {
actionstr = actionstr.toLowerCase();
for (String subaction : actionstr.split(",")) {
String action = subaction.split("[=:]")[0];
SubActionStruct subaction_struct = null;
if (action.equals("output")) {
subaction_struct = StaticFlowEntries.decode_output(subaction, log);
}
else if (action.equals("enqueue")) {
subaction_struct = decode_enqueue(subaction, log);
}
else if (action.equals("strip-vlan")) {
subaction_struct = decode_strip_vlan(subaction, log);
}
else if (action.equals("set-vlan-id")) {
subaction_struct = decode_set_vlan_id(subaction, log);
}
else if (action.equals("set-vlan-priority")) {
subaction_struct = decode_set_vlan_priority(subaction, log);
}
else if (action.equals("set-src-mac")) {
subaction_struct = decode_set_src_mac(subaction, log);
}
else if (action.equals("set-dst-mac")) {
subaction_struct = decode_set_dst_mac(subaction, log);
}
else if (action.equals("set-tos-bits")) {
subaction_struct = decode_set_tos_bits(subaction, log);
}
else if (action.equals("set-src-ip")) {
subaction_struct = decode_set_src_ip(subaction, log);
}
else if (action.equals("set-dst-ip")) {
subaction_struct = decode_set_dst_ip(subaction, log);
}
else if (action.equals("set-src-port")) {
subaction_struct = decode_set_src_port(subaction, log);
}
else if (action.equals("set-dst-port")) {
subaction_struct = decode_set_dst_port(subaction, log);
}
else {
log.error("Unexpected action '{}', '{}'", action, subaction);
}
if (subaction_struct != null) {
actions.add(subaction_struct.action);
actionsLength += subaction_struct.len;
}
}
}
log.debug("action {}", actions);
flowMod.setActions(actions);
flowMod.setLengthU(OFFlowMod.MINIMUM_LENGTH + actionsLength);
}
示例8: setDefaultRules
import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
private void setDefaultRules()//default rules
{
Iterator<Entry<Long, swInfo>> ite = color.entrySet().iterator();
while(ite.hasNext())
{
List<OFMessage> messages = new ArrayList<OFMessage>();//contain all default rules of a sw
Entry<Long, swInfo> entry = ite.next();
Long DPID = entry.getKey();
//Integer COLOR = entry.getValue().getCOLOR();
Iterator<Long> neighbor = entry.getValue().getNeighbors().iterator();
while(neighbor.hasNext())
{
Long neighbor_sw = neighbor.next();
Integer neighbor_color = color.get(neighbor_sw).getCOLOR();
//the default tag of (000) is reserved for the production traffic and is not used during the tag assignment process
OFMatch match = new OFMatch();
match.setDataLayerVirtualLanPriorityCodePoint(neighbor_color.byteValue());
match.setWildcards(~(OFMatch.OFPFW_DL_VLAN_PCP ));
OFFlowMod mod = (OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD);
mod.setMatch(match);
mod.setCommand(OFFlowMod.OFPFC_ADD);
mod.setIdleTimeout((short)0);
mod.setHardTimeout((short)0);
mod.setPriority((short)(32767));
mod.setBufferId(OFPacketOut.BUFFER_ID_NONE);
mod.setFlags((short)(1 << 0));
List<OFAction> actions = new ArrayList<OFAction>();
actions.add(new OFActionOutput(OFPort.OFPP_CONTROLLER.getValue(),(short)0xFFFF));
mod.setActions(actions);
mod.setLengthU(OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH);
messages.add(mod);
}
//System.out.println(messages.size());
writeOFMessagesToSwitch(DPID, messages);
}
}
示例9: add
import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Adds flow for given switch, outgoing port, and incoming packet.
* Constructs {@link OFMatch} from the incoming packet and instructs switch
* to send all packets from the flow to be sent to given outgoing port. The
* received packet is sent do switch for forwarding.
*
* @param sw swithc
* @param floodlightProvider Floodlight controller
* @param cntx Floodlight context
* @param outPort outgoing port
* @param pi incoming packet
*/
public static void add(IOFSwitch sw, IFloodlightProviderService floodlightProvider, FloodlightContext cntx, short outPort, OFPacketIn pi) {
logger.debug("add(IOFSwitch,IFloodlightProviderService,FloodlightContext,short OFPacketIn) begin");
OFFlowMod flowMod = (OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD);
// Parse the received packet
OFMatch match = new OFMatch();
match.loadFromPacket(pi.getPacketData(), pi.getInPort());
match.setWildcards(0);
flowMod.setMatch(match);
flowMod.setCommand(OFFlowMod.OFPFC_ADD);
flowMod.setIdleTimeout((short) 11);
flowMod.setHardTimeout((short) 0);
flowMod.setPriority((short) 50);
flowMod.setBufferId(OFPacketOut.BUFFER_ID_NONE);
flowMod.setFlags((short) 1);
List<OFAction> actions = new ArrayList<>();
actions.add(new OFActionOutput().setPort(outPort));
flowMod.setActions(actions);
flowMod.setLengthU(OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH);
OFPacketOut po = (OFPacketOut) floodlightProvider.getOFMessageFactory().getMessage(OFType.PACKET_OUT);
po.setActions(actions);
po.setActionsLength((short) OFActionOutput.MINIMUM_LENGTH);
short poLength = (short) (po.getActionsLength() + OFPacketOut.MINIMUM_LENGTH);
po.setBufferId(pi.getBufferId());
po.setInPort(pi.getInPort());
if (pi.getBufferId() == OFPacketOut.BUFFER_ID_NONE) {
byte[] packetData = pi.getPacketData();
poLength += packetData.length;
po.setPacketData(packetData);
}
po.setLength(poLength);
List<OFMessage> msglist = new ArrayList<>();
msglist.add(flowMod);
msglist.add(po);
try {
sw.write(msglist, cntx);
sw.flush();
logger.debug(String.format("Flow rule (out port %d) added to switch %s", outPort, sw.getStringId()));
} catch (IOException ex) {
logger.error(String.format("Error while adding flow rule (out port %d) to switch %s", outPort, sw.getStringId()), ex);
}
logger.debug("add(IOFSwitch,IFloodlightProviderService,FloodlightContext,short OFPacketIn) end");
}