当前位置: 首页>>代码示例>>Java>>正文


Java OFFlowMod.setFlags方法代码示例

本文整理汇总了Java中org.openflow.protocol.OFFlowMod.setFlags方法的典型用法代码示例。如果您正苦于以下问题:Java OFFlowMod.setFlags方法的具体用法?Java OFFlowMod.setFlags怎么用?Java OFFlowMod.setFlags使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openflow.protocol.OFFlowMod的用法示例。


在下文中一共展示了OFFlowMod.setFlags方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkExpiredFlows

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
public void checkExpiredFlows(){
	log.debug("Checking for expired flows");
	Iterator<FlowTimeout> it = this.timeouts.iterator();
	while(it.hasNext()){
		FlowTimeout timeout = it.next();
		if(timeout.isExpired()){
			log.debug("Removing Flow that has timed out");
			it.remove();
			OFFlowMod flow = timeout.getFlow();
			flow.setOutPort(OFPort.OFPP_NONE);
			flow.setCommand(OFFlowMod.OFPFC_DELETE_STRICT);
			flow.setHardTimeout((short)0);
			flow.setIdleTimeout((short)0);
			flow.setFlags(OFFlowMod.OFPFF_SEND_FLOW_REM);
			this.toSwitch((OFMessage) flow,  timeout.getContext());				
		}
	}
}
 
开发者ID:GlobalNOC,项目名称:FlowSpaceFirewall,代码行数:19,代码来源:Proxy.java

示例2: initDefaultFlowMod

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
 * Sets defaults for an OFFlowMod
 * @param fm The OFFlowMod to set defaults for
 * @param entryName The name of the entry. Used to compute the cookie.
 */
public static void initDefaultFlowMod(OFFlowMod fm, String entryName) {
    fm.setIdleTimeout((short) 0);   // infinite
    fm.setHardTimeout((short) 0);   // infinite
    fm.setBufferId(OFPacketOut.BUFFER_ID_NONE);
    fm.setCommand((short) 0);
    fm.setFlags((short) 0);
    fm.setOutPort(OFPort.OFPP_NONE.getValue());
    fm.setCookie(computeEntryCookie(fm, 0, entryName));  
    fm.setPriority(Short.MAX_VALUE);
}
 
开发者ID:JianqingJiang,项目名称:QoS-floodlight,代码行数:16,代码来源:StaticFlowEntries.java

示例3: doDropFlow

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
 * Writes a FlowMod to a switch that inserts a drop flow.
 * @param sw The switch to write the FlowMod to.
 * @param pi The corresponding OFPacketIn. Used to create the OFMatch structure.
 * @param cntx The FloodlightContext that gets passed to the switch.
 */
protected void doDropFlow(IOFSwitch sw, OFPacketIn pi, FloodlightContext cntx) {
    if (log.isTraceEnabled()) {
        log.trace("doDropFlow pi={} srcSwitch={}",
                new Object[] { pi, sw });
    }

    if (sw == null) {
        log.warn("Switch is null, not installing drop flowmod for PacketIn {}", pi);
        return;
    }

    // Create flow-mod based on packet-in and src-switch
    OFFlowMod fm = 
        (OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD);
    OFMatch match = new OFMatch();
    match.loadFromPacket(pi.getPacketData(), pi.getInPort());
    List<OFAction> actions = new ArrayList<OFAction>(); // no actions = drop
    long cookie = AppCookie.makeCookie(APP_ID, 0);
    fm.setCookie(cookie)
    .setIdleTimeout(ForwardingBase.FLOWMOD_DEFAULT_IDLE_TIMEOUT)
    .setHardTimeout(ForwardingBase.FLOWMOD_DEFAULT_HARD_TIMEOUT)
    .setBufferId(OFPacketOut.BUFFER_ID_NONE)
    .setMatch(match)
    .setActions(actions)
    .setLengthU(OFFlowMod.MINIMUM_LENGTH);
    fm.setFlags(OFFlowMod.OFPFF_SEND_FLOW_REM);
    try {
        if (log.isTraceEnabled()) {
            log.trace("write drop flow-mod srcSwitch={} match={} " + 
                      "pi={} flow-mod={}",
                      new Object[] {sw, match, pi, fm});
        }
        sw.write(fm, cntx);
    } catch (IOException e) {
        log.error("Failure writing drop flow mod", e);
    }
    return;
}
 
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:45,代码来源:VirtualNetworkFilter.java

示例4: 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");
}
 
开发者ID:smartenit-eu,项目名称:smartenit,代码行数:45,代码来源:Flows.java

示例5: 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");
}
 
开发者ID:smartenit-eu,项目名称:smartenit,代码行数:42,代码来源:Flows.java

示例6: writeFlowMod

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
 * Writes a OFFlowMod to a switch.
 * @param sw The switch tow rite the flowmod to.
 * @param command The FlowMod actions (add, delete, etc).
 * @param bufferId The buffer ID if the switch has buffered the packet.
 * @param match The OFMatch structure to write.
 * @param outPort The switch port to output it to.
 */
private void writeFlowMod(IOFSwitch sw, short command, int bufferId,
        OFMatch match, short outPort) {
    // from openflow 1.0 spec - need to set these on a struct ofp_flow_mod:
    // struct ofp_flow_mod {
    //    struct ofp_header header;
    //    struct ofp_match match; /* Fields to match */
    //    uint64_t cookie; /* Opaque controller-issued identifier. */
    //
    //    /* Flow actions. */
    //    uint16_t command; /* One of OFPFC_*. */
    //    uint16_t idle_timeout; /* Idle time before discarding (seconds). */
    //    uint16_t hard_timeout; /* Max time before discarding (seconds). */
    //    uint16_t priority; /* Priority level of flow entry. */
    //    uint32_t buffer_id; /* Buffered packet to apply to (or -1).
    //                           Not meaningful for OFPFC_DELETE*. */
    //    uint16_t out_port; /* For OFPFC_DELETE* commands, require
    //                          matching entries to include this as an
    //                          output port. A value of OFPP_NONE
    //                          indicates no restriction. */
    //    uint16_t flags; /* One of OFPFF_*. */
    //    struct ofp_action_header actions[0]; /* The action length is inferred
    //                                            from the length field in the
    //                                            header. */
    //    };

    OFFlowMod flowMod = (OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD);
    flowMod.setMatch(match);
    flowMod.setCookie(LearningSwitch.LEARNING_SWITCH_COOKIE);
    flowMod.setCommand(command);
    flowMod.setIdleTimeout(LearningSwitch.FLOWMOD_DEFAULT_IDLE_TIMEOUT);
    flowMod.setHardTimeout(LearningSwitch.FLOWMOD_DEFAULT_HARD_TIMEOUT);
    flowMod.setPriority(LearningSwitch.FLOWMOD_PRIORITY);
    flowMod.setBufferId(bufferId);
    flowMod.setOutPort((command == OFFlowMod.OFPFC_DELETE) ? outPort : OFPort.OFPP_NONE.getValue());
    flowMod.setFlags((command == OFFlowMod.OFPFC_DELETE) ? 0 : (short) (1 << 0)); // OFPFF_SEND_FLOW_REM

    // set the ofp_action_header/out actions:
    // from the openflow 1.0 spec: need to set these on a struct ofp_action_output:
    // uint16_t type; /* OFPAT_OUTPUT. */
    // uint16_t len; /* Length is 8. */
    // uint16_t port; /* Output port. */
    // uint16_t max_len; /* Max length to send to controller. */
    // type/len are set because it is OFActionOutput,
    // and port, max_len are arguments to this constructor
    flowMod.setActions(Arrays.asList((OFAction) new OFActionOutput(outPort, (short) 0xffff)));
    flowMod.setLength((short) (OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH));

    if (log.isTraceEnabled()) {
        log.trace("{} {} flow mod {}",
                  new Object[]{ sw, (command == OFFlowMod.OFPFC_DELETE) ? "deleting" : "adding", flowMod });
    }

    counterStore.updatePktOutFMCounterStoreLocal(sw, flowMod);

    // and write it out
    try {
        sw.write(flowMod, null);
    } catch (IOException e) {
        log.error("Failed to write {} to switch {}", new Object[]{ flowMod, sw }, e);
    }
}
 
开发者ID:JianqingJiang,项目名称:QoS-floodlight,代码行数:70,代码来源:LearningSwitch.java

示例7: writeFlowMod

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
 * Writes a OFFlowMod to a switch.
 * @param sw The switch tow rite the flowmod to.
 * @param command The FlowMod actions (add, delete, etc).
 * @param bufferId The buffer ID if the switch has buffered the packet.
 * @param match The OFMatch structure to write.
 * @param outPort The switch port to output it to.
 */
private void writeFlowMod(IOFSwitch sw, short command, int bufferId,
        OFMatch match, short outPort) {
    // from openflow 1.0 spec - need to set these on a struct ofp_flow_mod:
    // struct ofp_flow_mod {
    //    struct ofp_header header;
    //    struct ofp_match match; /* Fields to match */
    //    uint64_t cookie; /* Opaque controller-issued identifier. */
    //
    //    /* Flow actions. */
    //    uint16_t command; /* One of OFPFC_*. */
    //    uint16_t idle_timeout; /* Idle time before discarding (seconds). */
    //    uint16_t hard_timeout; /* Max time before discarding (seconds). */
    //    uint16_t priority; /* Priority level of flow entry. */
    //    uint32_t buffer_id; /* Buffered packet to apply to (or -1).
    //                           Not meaningful for OFPFC_DELETE*. */
    //    uint16_t out_port; /* For OFPFC_DELETE* commands, require
    //                          matching entries to include this as an
    //                          output port. A value of OFPP_NONE
    //                          indicates no restriction. */
    //    uint16_t flags; /* One of OFPFF_*. */
    //    struct ofp_action_header actions[0]; /* The action length is inferred
    //                                            from the length field in the
    //                                            header. */
    //    };
       
    OFFlowMod flowMod = (OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD);
    flowMod.setMatch(match);
    flowMod.setCookie(LearningSwitch.LEARNING_SWITCH_COOKIE);
    flowMod.setCommand(command);
    flowMod.setIdleTimeout(LearningSwitch.IDLE_TIMEOUT_DEFAULT);
    flowMod.setHardTimeout(LearningSwitch.HARD_TIMEOUT_DEFAULT);
    flowMod.setPriority(LearningSwitch.PRIORITY_DEFAULT);
    flowMod.setBufferId(bufferId);
    flowMod.setOutPort((command == OFFlowMod.OFPFC_DELETE) ? outPort : OFPort.OFPP_NONE.getValue());
    flowMod.setFlags((command == OFFlowMod.OFPFC_DELETE) ? 0 : (short) (1 << 0)); // OFPFF_SEND_FLOW_REM

    // set the ofp_action_header/out actions:
    // from the openflow 1.0 spec: need to set these on a struct ofp_action_output:
    // uint16_t type; /* OFPAT_OUTPUT. */
    // uint16_t len; /* Length is 8. */
    // uint16_t port; /* Output port. */
    // uint16_t max_len; /* Max length to send to controller. */
    // type/len are set because it is OFActionOutput,
    // and port, max_len are arguments to this constructor
    flowMod.setActions(Arrays.asList((OFAction) new OFActionOutput(outPort, (short) 0xffff)));
    flowMod.setLength((short) (OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH));

    if (log.isTraceEnabled()) {
        log.trace("{} {} flow mod {}", 
                  new Object[]{ sw, (command == OFFlowMod.OFPFC_DELETE) ? "deleting" : "adding", flowMod });
    }

    counterStore.updatePktOutFMCounterStore(sw, flowMod);
    
    // and write it out
    try {
        sw.write(flowMod, null);
    } catch (IOException e) {
        log.error("Failed to write {} to switch {}", new Object[]{ flowMod, sw }, e);
    }
}
 
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:70,代码来源:LearningSwitch.java

示例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);
	}
}
 
开发者ID:shao-you,项目名称:SDN-Traceroute,代码行数:42,代码来源:Traceroute.java

示例9: doDropFlow

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
@LogMessageDoc(level="ERROR",
        message="Failure writing deny flow mod",
        explanation=ioerrorFlowMod,
        recommendation=LogMessageDoc.CHECK_SWITCH)
protected void doDropFlow(OFPacketIn pi, 
                          IRoutingDecision decision, 
                          ListenerContext cntx) {        
    if (!validateDecision(decision)) {
        return;
    }

    // Initialize data from decision (validation above ensures that they 
    // all not null)
    Map<Long, IOFSwitch> switches = controllerProvider.getSwitches();
    IOFSwitch srcSwitch = 
            switches.get(decision.getSourcePort().getSwitchDPID());

    if (log.isTraceEnabled()) {
        log.trace("doDropFlow pi={} decision={} srcSwitch={}",
                new Object[] { pi, decision, srcSwitch });
    }

    if (srcSwitch == null)
        return;

    // Create flow-mod based on packet-in and src-switch
    OFFlowMod fm = 
            (OFFlowMod) controllerProvider.getOFMessageFactory().
                getMessage(OFType.FLOW_MOD);
    OFMatch match = new OFMatch();
    match.loadFromPacket(pi.getPacketData(), pi.getInPort());
    List<OFAction> actions = new ArrayList<OFAction>();
    match = wildcard(match, srcSwitch, decision.getWildcards());
    fm.setCookie(appCookie)
    .setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT)
    .setHardTimeout(decision.getHardTimeout())
    .setPriority(accessPriority)
    .setBufferId(OFPacketOut.BUFFER_ID_NONE)
    .setMatch(match)
    .setActions(actions)
    .setLengthU(OFFlowMod.MINIMUM_LENGTH); // +OFActionOutput.MINIMUM_LENGTH);
    fm.setFlags(OFFlowMod.OFPFF_SEND_FLOW_REM);
    try {
        if (log.isTraceEnabled()) {
            log.trace("write drop flow-mod srcSwitch={} match={} " + 
                      "pi={} flow-mod={}",
                      new Object[] {srcSwitch, match, pi, fm});
        }
        counterStore.updatePktOutFMCounterStoreLocal(srcSwitch, fm);
        srcSwitch.write(fm, cntx);
        OFMatchWithSwDpid ofmWithSwDpid = new OFMatchWithSwDpid(match, srcSwitch.getId());
        betterFlowCacheMgr.addFlow(cntx, ofmWithSwDpid, appCookie,
                decision.getSourcePort(), fm.getPriority(),
                FlowCacheObj.FCActionDENY);
    }
    catch (IOException e) {
        log.error("Failure writing deny flow mod", e);
    }
    return;
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:61,代码来源:Forwarding.java

示例10: doDropReconciledFlowMod

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
@Override
@LogMessageDoc(level="WARN",
    message="No matching switch with dpid {dpid} when trying to" +
            " install a DROP flow.",
    explanation="The switch has likely disconnected from the controller.",
    recommendation=LogMessageDoc.CHECK_SWITCH)
public void doDropReconciledFlowMod(OFMatchReconcile ofmRc) {
    // Get the source switch
    IOFSwitch swsrcSwitch = controllerProvider.getSwitches().
            get(ofmRc.ofmWithSwDpid.getSwitchDataPathId());
    
    // If the switch is not connected, NO-OP
    if (swsrcSwitch == null) {
        log.warn("No matching switch with dpid {} when trying to install a DROP flow.",
                    HexString.toHexString(ofmRc.ofmWithSwDpid.getSwitchDataPathId()));
        return;
    }
    
    /* Set the action to drop at the source switch for this
     * flow-mod. If we delete the flow-mod instead then
     * controller may get a large number of packet-ins.
     */
    OFFlowMod fm = (OFFlowMod) controllerProvider.
            getOFMessageFactory().getMessage(OFType.FLOW_MOD);
    List<OFAction> actions = new ArrayList<OFAction>();
    fm.setIdleTimeout(FLOWMOD_DEFAULT_IDLE_TIMEOUT)
    .setHardTimeout(FLOWMOD_DEFAULT_HARD_TIMEOUT)
    .setPriority(accessPriority)
    .setBufferId(OFPacketOut.BUFFER_ID_NONE)
    .setCookie(ofmRc.cookie)
    .setIdleTimeout((short)5)
    .setMatch(ofmRc.ofmWithSwDpid.getOfMatch())
    .setActions(actions)
    .setLengthU(OFFlowMod.MINIMUM_LENGTH);
    fm.setFlags(OFFlowMod.OFPFF_SEND_FLOW_REM);
    fm.setCommand(OFFlowMod.OFPFC_MODIFY);
    /* Request flow mod */
    try {
        swsrcSwitch.write(fm, null);
        swsrcSwitch.flush();
        if (log.isTraceEnabled()) {
            log.trace("Programmed drop flow-mod {} at {}", fm, swsrcSwitch);
        }
        betterFlowCacheMgr.addFlow(
                ofmRc.appInstName, ofmRc.ofmWithSwDpid, ofmRc.cookie,
                swsrcSwitch.getId(),
                ofmRc.ofmWithSwDpid.getOfMatch().getInputPort(),
                fm.getPriority(), FlowCacheObj.FCActionDENY);
    } catch (IOException e) {
        log.error("Failure writing deny flow mod", e);
    }
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:53,代码来源:Forwarding.java

示例11: writeFlowMod

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
 * Writes a OFFlowMod to a switch.
 * @param sw The switch tow rite the flowmod to.
 * @param command The FlowMod actions (add, delete, etc).
 * @param bufferId The buffer ID if the switch has buffered the packet.
 * @param match The OFMatch structure to write.
 * @param outPort The switch port to output it to.
 */
private void writeFlowMod(IOFSwitch sw, short command, int bufferId,
        OFMatch match, short outPort) {
    // from openflow 1.0 spec - need to set these on a struct ofp_flow_mod:
    // struct ofp_flow_mod {
    //    struct ofp_header header;
    //    struct ofp_match match; /* Fields to match */
    //    uint64_t cookie; /* Opaque controller-issued identifier. */
    //
    //    /* Flow actions. */
    //    uint16_t command; /* One of OFPFC_*. */
    //    uint16_t idle_timeout; /* Idle time before discarding (seconds). */
    //    uint16_t hard_timeout; /* Max time before discarding (seconds). */
    //    uint16_t priority; /* Priority level of flow entry. */
    //    uint32_t buffer_id; /* Buffered packet to apply to (or -1).
    //                           Not meaningful for OFPFC_DELETE*. */
    //    uint16_t out_port; /* For OFPFC_DELETE* commands, require
    //                          matching entries to include this as an
    //                          output port. A value of OFPP_NONE
    //                          indicates no restriction. */
    //    uint16_t flags; /* One of OFPFF_*. */
    //    struct ofp_action_header actions[0]; /* The action length is inferred
    //                                            from the length field in the
    //                                            header. */
    //    };
       
    OFFlowMod flowMod = (OFFlowMod) controllerProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD);
    flowMod.setMatch(match);
    flowMod.setCookie(LearningSwitch.LEARNING_SWITCH_COOKIE);
    flowMod.setCommand(command);
    flowMod.setIdleTimeout(LearningSwitch.FLOWMOD_DEFAULT_IDLE_TIMEOUT);
    flowMod.setHardTimeout(LearningSwitch.FLOWMOD_DEFAULT_HARD_TIMEOUT);
    flowMod.setPriority(LearningSwitch.FLOWMOD_PRIORITY);
    flowMod.setBufferId(bufferId);
    flowMod.setOutPort((command == OFFlowMod.OFPFC_DELETE) ? outPort : OFPort.OFPP_NONE.getValue());
    flowMod.setFlags((command == OFFlowMod.OFPFC_DELETE) ? 0 : (short) (1 << 0)); // OFPFF_SEND_FLOW_REM

    // set the ofp_action_header/out actions:
    // from the openflow 1.0 spec: need to set these on a struct ofp_action_output:
    // uint16_t type; /* OFPAT_OUTPUT. */
    // uint16_t len; /* Length is 8. */
    // uint16_t port; /* Output port. */
    // uint16_t max_len; /* Max length to send to controller. */
    // type/len are set because it is OFActionOutput,
    // and port, max_len are arguments to this constructor
    flowMod.setActions(Arrays.asList((OFAction) new OFActionOutput(outPort, (short) 0xffff)));
    flowMod.setLength((short) (OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH));

    if (log.isTraceEnabled()) {
        log.trace("{} {} flow mod {}", 
                  new Object[]{ sw, (command == OFFlowMod.OFPFC_DELETE) ? "deleting" : "adding", flowMod });
    }

    counterStore.updatePktOutFMCounterStore(sw, flowMod);
    
    // and write it out
    try {
        sw.write(flowMod, null);
    } catch (IOException e) {
        log.error("Failed to write {} to switch {}", new Object[]{ flowMod, sw }, e);
    }
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:70,代码来源:LearningSwitch.java

示例12: testForwardWithHints

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
@Test
public void testForwardWithHints() throws Exception {


    // Mock decision
    expect(decision.getRoutingAction()).andReturn(IRoutingDecision.RoutingAction.FORWARD).atLeastOnce();
    expect(decision.getWildcards()).andReturn(new Integer(expected_wildcards & ~OFMatch.OFPFW_IN_PORT)).atLeastOnce();
    expect(decision.getHardTimeout()).
    andReturn(ForwardingBase.FLOWMOD_DEFAULT_HARD_TIMEOUT).atLeastOnce();

    // Set destination as sw2 and Mock route
    dstDevices.add(dstDevice1);
    Route route = new Route(1L, 2L);
    route.setPath(new ArrayList<NodePortTuple>());
    route.getPath().add(new NodePortTuple(1L, (short)1));
    route.getPath().add(new NodePortTuple(1L, (short)3));
    route.getPath().add(new NodePortTuple(2L, (short)1));
    route.getPath().add(new NodePortTuple(2L, (short)3));
    long cookie = forwarding.getHashByMac(dstDevice1.getMACAddress());
    expect(routingEngine.getRoute(1L, (short)1, 2L, (short)3, cookie, true)).andReturn(route).atLeastOnce();

    // Expected Flow-mods
    OFMatch match = new OFMatch();
    match.loadFromPacket(testPacketSerialized, (short) 1);
    OFActionOutput action = new OFActionOutput((short)3, (short)0xffff);
    List<OFAction> actions = new ArrayList<OFAction>();
    actions.add(action);

    OFFlowMod fm1 = new OFFlowMod();
    fm1.setIdleTimeout((short)5)
    .setPriority(forwarding.getAccessPriority())
    .setMatch(match.clone()
            .setWildcards(expected_wildcards & ~OFMatch.OFPFW_IN_PORT))
            .setActions(actions)
            .setBufferId(OFPacketOut.BUFFER_ID_NONE)
            .setCookie(2L << 52)
            .setLengthU(OFFlowMod.MINIMUM_LENGTH+OFActionOutput.MINIMUM_LENGTH);
    OFFlowMod fm2 = fm1.clone();
    fm1.setFlags((short)1);
    ((OFActionOutput)fm2.getActions().get(0)).setPort((short) 3);

    // Record expected packet-outs/flow-mods
    sw1.write(fm1, cntx);
    sw1.write(packetOut, cntx);
    sw2.write(fm2, cntx);

    // Reset mocks, trigger the packet in, and validate results
    reset(topology);
    expect(topology.getL2DomainId(1L)).andReturn(1L).anyTimes();
    expect(topology.getL2DomainId(2L)).andReturn(1L).anyTimes();
    expect(topology.getL2DomainId(3L)).andReturn(3L).anyTimes();
    expect(topology.getL2DomainId(1L, false)).andReturn(1L).anyTimes();
    expect(topology.getL2DomainId(2L, false)).andReturn(1L).anyTimes();
    expect(topology.getL2DomainId(3L, false)).andReturn(3L).anyTimes();
    expect(topology.getL2DomainId(1L, true)).andReturn(1L).anyTimes();
    expect(topology.getL2DomainId(2L, true)).andReturn(1L).anyTimes();
    expect(topology.getL2DomainId(3L, true)).andReturn(3L).anyTimes();
    expect(topology.getIncomingSwitchPort(1, (short)1, 2, (short)3, true)).andReturn(new NodePortTuple(1, (short)1)).anyTimes();
    expect(topology.isAttachmentPointPort(1L, (short)1)).andReturn(true).anyTimes();
    expect(topology.isAttachmentPointPort(2L, (short)3)).andReturn(true).anyTimes();
    expect(topology.isAttachmentPointPort(1L, (short)1, true)).andReturn(true).anyTimes();
    expect(topology.getOutgoingSwitchPort(1, (short)1, 2, (short)3, true)).andReturn(new NodePortTuple(2, (short)3)).anyTimes();
    expect(topology.isAllowed(EasyMock.anyLong(), EasyMock.anyShort())).andReturn(true).anyTimes();


    replay(sw1, sw2, routingEngine, decision, topology);
    forwarding.receive(sw1, this.packetIn, cntx);
    verify(sw1, sw2, routingEngine, decision);
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:70,代码来源:ForwardingTest.java

示例13: testDetectTunnelTrafficCommon

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
 * Test set-up that is common to testTunnelTraffic* unit tests.
 * @throws Exception
 */
private void testDetectTunnelTrafficCommon() throws Exception {
    // Mock decision
    expect(decision.getRoutingAction()).andReturn(IRoutingDecision.RoutingAction.FORWARD).atLeastOnce();
    expect(decision.getWildcards()).andReturn(null).atLeastOnce();
    expect(decision.getHardTimeout()).
    andReturn(ForwardingBase.FLOWMOD_DEFAULT_HARD_TIMEOUT).atLeastOnce();

    // Set destination as sw2 and Mock route
    dstDevices.add(dstDevice1);

    // Expected Flow-mods
    OFMatch match = new OFMatch();
    match.loadFromPacket(testPacketSerialized, (short) 1);
    OFActionOutput action = new OFActionOutput((short)3, (short)0xffff);
    List<OFAction> actions = new ArrayList<OFAction>();
    actions.add(action);

    OFFlowMod fm1 = (OFFlowMod) mockControllerProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD);
    fm1.setIdleTimeout((short)5)
    .setPriority(forwarding.getAccessPriority())
    .setMatch(match.clone()
            .setWildcards(expected_wildcards))
            .setPriority(forwarding.getAccessPriority())
            .setActions(actions)
            .setBufferId(OFPacketOut.BUFFER_ID_NONE)
            .setCookie(2L << 52)
            .setLengthU(OFFlowMod.MINIMUM_LENGTH+OFActionOutput.MINIMUM_LENGTH);
    OFFlowMod fm2 = fm1.clone();
    fm1.setFlags((short)1); // set flow-mod-removal flag on src switch only
    ((OFActionOutput)fm2.getActions().get(0)).setPort((short) 3);

    sw1.write(capture(wc1), capture(fc1));
    expectLastCall().anyTimes();
    sw2.write(capture(wc2), capture(fc2));
    expectLastCall().anyTimes();

    // Reset mocks, trigger the packet in, and validate results
    reset(topology);
    expect(topology.getL2DomainId(1L)).andReturn(1L).anyTimes();
    expect(topology.getL2DomainId(2L)).andReturn(1L).anyTimes();
    expect(topology.getL2DomainId(3L)).andReturn(3L).anyTimes();
    expect(topology.getL2DomainId(1L, true)).andReturn(1L).anyTimes();
    expect(topology.getL2DomainId(2L, true)).andReturn(1L).anyTimes();
    expect(topology.getL2DomainId(3L, true)).andReturn(3L).anyTimes();
    expect(topology.getL2DomainId(1L, false)).andReturn(1L).anyTimes();
    expect(topology.getL2DomainId(2L, false)).andReturn(1L).anyTimes();
    expect(topology.getL2DomainId(3L, false)).andReturn(3L).anyTimes();
    expect(topology.isAttachmentPointPort(EasyMock.anyLong(), EasyMock.anyShort())).andReturn(true).anyTimes();
    expect(topology.isAttachmentPointPort(1L, (short)1, false)).andReturn(true).anyTimes();
    expect(topology.getIncomingSwitchPort(1, (short)1, 2, (short)3, false)).andReturn(new NodePortTuple(1, (short)1)).anyTimes();
    expect(topology.getOutgoingSwitchPort(1, (short)1, 2, (short)3, false)).andReturn(new NodePortTuple(2, (short)3)).anyTimes();
    expect(topology.isAllowed(EasyMock.anyLong(), EasyMock.anyShort())).andReturn(true).anyTimes();

    Route route = new Route(1L, 2L);
    route.setPath(new ArrayList<NodePortTuple>());
    route.getPath().add(new NodePortTuple(1L, (short)1));
    route.getPath().add(new NodePortTuple(1L, (short)3));
    route.getPath().add(new NodePortTuple(2L, (short)1));
    route.getPath().add(new NodePortTuple(2L, (short)3));
    long cookie = forwarding.getHashByMac(dstDevice1.getMACAddress());
    expect(routingEngine.getRoute(1L, (short)1, 2L, (short)3, cookie, false)).andReturn(route).anyTimes();

    // Mock tunnel service
    reset(tunnelManager);
    expect(tunnelManager.isTunnelEndpoint(anyObject(IDevice.class)))
            .andReturn(true).anyTimes();
    expect(tunnelManager.isTunnelEndpoint(null)).andReturn(false).anyTimes();
    expect(tunnelManager.getTunnelPortNumber(1L)).andReturn(new Short((short)100)).anyTimes();
    expect(tunnelManager.getTunnelPortNumber(2L)).andReturn(new Short((short)100)).anyTimes();

    reset(bettertopology);
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:77,代码来源:ForwardingTest.java

示例14: testForwardNOFViaTunnelOrigDestToOFSwLocal

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
@Test
public void testForwardNOFViaTunnelOrigDestToOFSwLocal() throws Exception {
    /*
     * Common setup for all NOFViaTunnelToOFSw tests
     */
    setupNOFViaTunnelToOFSwTest((short)1, (short)3, true, false);

    /*
     * Test specific setup
     */
    IDeviceService.fcStore.put(cntx,
                               IDeviceService.CONTEXT_DST_DEVICE,
                               device1);
    IDeviceService.fcStore.put(cntx,
                               IDeviceService.CONTEXT_ORIG_DST_DEVICE,
                               device4);
    dstDevices.add(device1);

    /*
     * Expected Flow-mods
     */
    OFMatch match = new OFMatch();
    match.loadFromPacket(testPacketSerialized, (short) 1);
    OFActionOutput action = new OFActionOutput((short)3, (short)0xffff);
    List<OFAction> actions = new ArrayList<OFAction>();
    actions.add(action);

    OFFlowMod fm1 = (OFFlowMod)mockControllerProvider
                               .getOFMessageFactory()
                               .getMessage(OFType.FLOW_MOD);
    fm1.setIdleTimeout((short)5)
       .setPriority(forwarding.getAccessPriority())
       .setMatch(match.clone()
            .setWildcards(expected_wildcards))
            .setPriority(forwarding.getAccessPriority())
            .setActions(actions)
            .setBufferId(OFPacketOut.BUFFER_ID_NONE)
            .setCookie(2L << 52)
            .setLengthU(OFFlowMod.MINIMUM_LENGTH+OFActionOutput.MINIMUM_LENGTH);
    fm1.setFlags((short)1); // set flow-mod-removal flag on src switch only

    /*
     * Capture writes of OFMessages(flowmods, packetout) to switches
     */
    sw1.write(capture(wc1), capture(fc1));
    expectLastCall().anyTimes();
    sw2.write(capture(wc2), capture(fc2));
    expectLastCall().anyTimes();

    /*
     * Replay mocks
     */
    replay(sw1, sw2, routingEngine, decision, topology, tunnelManager);

    /*
     * Finally the test
     */
    forwarding.receive(sw1, this.packetIn, cntx);

    /*
     * Verify
     */
    verify(sw1);
    verify(sw2);
    verify(routingEngine);
    verify(decision);
    verify(topology);
    verify(tunnelManager);

    assertTrue(wc1.hasCaptured());  // wc1 should get packetout + flowmod.
    assertFalse(wc2.hasCaptured());  // no flowmods on wc2
    List<OFMessage> msglist = wc1.getValues();
    for (OFMessage m: msglist) {
        if (m instanceof OFPacketOut)
            assertEquals(m, packetOut);
        else if (m instanceof OFFlowMod)
            assertEquals(m, fm1);
    }
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:80,代码来源:ForwardingTest.java


注:本文中的org.openflow.protocol.OFFlowMod.setFlags方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。