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


Java OFFlowMod.setCommand方法代码示例

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


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

示例1: del

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
 * Deletes flow for given switch and destination DC IP. 
 * Constructs {@link OFMatch} and instructs switch to delete particular flow from its flow table.
 * @param sw
 * @param floodlightProvider
 * @param cntx
 * @param dcIP
 * @param dcMask 
 */
public static void del(IOFSwitch sw, IFloodlightProviderService floodlightProvider, FloodlightContext cntx, String dcIP, int dcMask) {
    logger.debug("del(IOFSwitch,IFloodlightProviderService,FloodlightContext,short OFPacketIn) end");
    OFMatch match = new OFMatch();

    match.setDataLayerType(Ethernet.TYPE_IPv4);
    match.setNetworkDestination(IPv4.toIPv4Address(dcIP));
    int nw_dst_mask = ((1 << OFMatch.OFPFW_NW_DST_BITS) - 1) << dcMask;
    match.setWildcards(OFMatch.OFPFW_ALL & ~OFMatch.OFPFW_DL_TYPE & ~nw_dst_mask);

    OFFlowMod flowMod = (OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD);
    //OFFlowMod flowMod = new OFFlowMod(); <-without floodlightProvider
    flowMod.setMatch(match);
    flowMod.setType(OFType.FLOW_MOD);
    flowMod.setCommand(OFFlowMod.OFPFC_DELETE);

    try {
        sw.write(flowMod, null);
        sw.flush();
        logger.debug(String.format("Flow rule {} deleted from switch {}", match.toString(), sw.getStringId()));
    } catch (IOException ex) {
        logger.error(String.format("Unable to send delete flow message: ", ex.getMessage()));
    }
    logger.debug("del(IOFSwitch,IFloodlightProviderService,FloodlightContext,short OFPacketIn) end");
}
 
开发者ID:smartenit-eu,项目名称:smartenit,代码行数:34,代码来源:Flows.java

示例2: 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

示例3: 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();
			}
		}
	}
}
 
开发者ID:GlobalNOC,项目名称:FlowSpaceFirewall,代码行数:27,代码来源:FlowStatCache.java

示例4: 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

示例5: deleteStaticFlowEntry

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
@LogMessageDoc(level="ERROR",
        message="inconsistent internal state: no switch has rule {rule}",
        explanation="Inconsistent internat state discovered while " +
                "deleting a static flow rule",
        recommendation=LogMessageDoc.REPORT_CONTROLLER_BUG)
private void deleteStaticFlowEntry(String entryName) {
    String dpid = entry2dpid.remove(entryName);

    if (dpid == null) {
        // assume state has been cleared by deleteFlowsForSwitch() or
        // deleteAllFlows()
        return;
    }

    if (log.isDebugEnabled()) {
        log.debug("Sending delete flow mod for flow {} for switch {}", entryName, dpid);
    }

    // send flow_mod delete
    OFFlowMod flowMod = entriesFromStorage.get(dpid).get(entryName);
    flowMod.setCommand(OFFlowMod.OFPFC_DELETE_STRICT);

    if (entriesFromStorage.containsKey(dpid) &&
            entriesFromStorage.get(dpid).containsKey(entryName)) {
        entriesFromStorage.get(dpid).remove(entryName);
    } else {
        log.debug("Tried to delete non-existent entry {} for switch {}",
                entryName, dpid);
        return;
    }

    writeFlowModToSwitch(HexString.toLong(dpid), flowMod);
    return;
}
 
开发者ID:JianqingJiang,项目名称:QoS-floodlight,代码行数:35,代码来源:StaticFlowEntryPusher.java

示例6: deleteStaticFlowEntry

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
@LogMessageDoc(level="ERROR",
        message="inconsistent internal state: no switch has rule {rule}",
        explanation="Inconsistent internat state discovered while " +
        		"deleting a static flow rule",
        recommendation=LogMessageDoc.REPORT_CONTROLLER_BUG)
private boolean deleteStaticFlowEntry(String entryName) {
    String dpid = entry2dpid.get(entryName);
    if (log.isDebugEnabled()) {
        log.debug("Deleting flow {} for switch {}", entryName, dpid);
    }
    if (dpid == null) {
        log.error("inconsistent internal state: no switch has rule {}",
                entryName);
        return false;
    }
    
    // send flow_mod delete
    OFFlowMod flowMod = entriesFromStorage.get(dpid).get(entryName);
    flowMod.setCommand(OFFlowMod.OFPFC_DELETE_STRICT);

    if (entriesFromStorage.containsKey(dpid) && 
            entriesFromStorage.get(dpid).containsKey(entryName)) {
        entriesFromStorage.get(dpid).remove(entryName);
    } else { 
        log.debug("Tried to delete non-existent entry {} for switch {}", 
                entryName, dpid);
        return false;
    }
    
    writeFlowModToSwitch(HexString.toLong(dpid), flowMod);
    return true;
}
 
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:33,代码来源:StaticFlowEntryPusher.java

示例7: deleteStaticFlowEntry

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
@LogMessageDoc(level="ERROR",
        message="inconsistent internal state: no switch has rule {rule}",
        explanation="Inconsistent internat state discovered while " +
                "deleting a static flow rule",
        recommendation=LogMessageDoc.REPORT_CONTROLLER_BUG)
private void deleteStaticFlowEntry(String entryName) {
    String dpid = entry2dpid.remove(entryName);
    
    if (dpid == null) {
        // assume state has been cleared by deleteFlowsForSwitch() or
        // deleteAllFlows()
        return;
    }
    
    if (log.isDebugEnabled()) {
        log.debug("Sending delete flow mod for flow {} for switch {}", entryName, dpid);
    }
    
    // send flow_mod delete
    OFFlowMod flowMod = entriesFromStorage.get(dpid).get(entryName);
    flowMod.setCommand(OFFlowMod.OFPFC_DELETE_STRICT);

    if (entriesFromStorage.containsKey(dpid) && 
            entriesFromStorage.get(dpid).containsKey(entryName)) {
        entriesFromStorage.get(dpid).remove(entryName);
    } else { 
        log.debug("Tried to delete non-existent entry {} for switch {}", 
                entryName, dpid);
        return;
    }
    
    writeFlowModToSwitch(HexString.toLong(dpid), flowMod);
    return;
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:35,代码来源:StaticFlowEntryPusher.java

示例8: 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

示例9: 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();
	}
	
}
 
开发者ID:GlobalNOC,项目名称:FlowSpaceFirewall,代码行数:32,代码来源:Proxy.java

示例10: 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

示例11: rowsModified

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
@Override
public void rowsModified(String tableName, Set<Object> rowKeys) {
    // This handles both rowInsert() and rowUpdate()
    log.debug("Modifying Table {}", tableName);
    HashMap<String, Map<String, OFFlowMod>> entriesToAdd =
        new HashMap<String, Map<String, OFFlowMod>>();
    // build up list of what was added
    for (Object key: rowKeys) {
        IResultSet resultSet = storageSource.getRow(tableName, key);
        Iterator<IResultSet> it = resultSet.iterator();
        while (it.hasNext()) {
            Map<String, Object> row = it.next().getRow();
            parseRow(row, entriesToAdd);
        }
    }
    // batch updates by switch and blast them out
    for (String dpid : entriesToAdd.keySet()) {
        if (!entriesFromStorage.containsKey(dpid))
            entriesFromStorage.put(dpid, new HashMap<String, OFFlowMod>());

        List<OFMessage> outQueue = new ArrayList<OFMessage>();
        for(String entry : entriesToAdd.get(dpid).keySet()) {
            OFFlowMod newFlowMod = entriesToAdd.get(dpid).get(entry);
            //OFFlowMod oldFlowMod = entriesFromStorage.get(dpid).get(entry);
            OFFlowMod oldFlowMod = null;
            String dpidOldFlowMod = entry2dpid.get(entry);
            if (dpidOldFlowMod != null) {
                oldFlowMod = entriesFromStorage.get(dpidOldFlowMod).remove(entry);
            }
            if (oldFlowMod != null && newFlowMod != null) {
                // set the new flow mod to modify a pre-existing rule if these fields match
                if(oldFlowMod.getMatch().equals(newFlowMod.getMatch())
                        && oldFlowMod.getCookie() == newFlowMod.getCookie()
                        && oldFlowMod.getPriority() == newFlowMod.getPriority()){
                    newFlowMod.setCommand(OFFlowMod.OFPFC_MODIFY_STRICT);
                // if they don't match delete the old flow
                } else{
                    oldFlowMod.setCommand(OFFlowMod.OFPFC_DELETE_STRICT);
                    if (dpidOldFlowMod.equals(dpid)) {
                        outQueue.add(oldFlowMod);
                    } else {
                        writeOFMessageToSwitch(HexString.toLong(dpidOldFlowMod), oldFlowMod);
                    }
                }
            }
            // write the new flow
            if (newFlowMod != null) {
                entriesFromStorage.get(dpid).put(entry, newFlowMod);
                outQueue.add(newFlowMod);
                entry2dpid.put(entry, dpid);
            } else {
                entriesFromStorage.get(dpid).remove(entry);
                entry2dpid.remove(entry);
            }
        }
        writeOFMessagesToSwitch(HexString.toLong(dpid), outQueue);
    }
}
 
开发者ID:JianqingJiang,项目名称:QoS-floodlight,代码行数:59,代码来源:StaticFlowEntryPusher.java

示例12: 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

示例13: rowsModified

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
 * This handles both rowInsert() and rowUpdate()
 */

@Override
public void rowsModified(String tableName, Set<Object> rowKeys) {
    log.debug("Modifying Table {}", tableName);

    HashMap<String, Map<String, OFFlowMod>> entriesToAdd = 
        new HashMap<String, Map<String, OFFlowMod>>();
    // build up list of what was added 
    for(Object key: rowKeys) {
        IResultSet resultSet = storageSource.getRow(tableName, key);
        for (Iterator<IResultSet> it = resultSet.iterator(); it.hasNext();) {
            Map<String, Object> row = it.next().getRow();
            parseRow(row, entriesToAdd);
        }            
    }
    // batch updates by switch and blast them out
    for (String dpid : entriesToAdd.keySet()) {
        if (!entriesFromStorage.containsKey(dpid))
            entriesFromStorage.put(dpid, new HashMap<String, OFFlowMod>());
        List<OFMessage> outQueue = new ArrayList<OFMessage>();
        for(String entry : entriesToAdd.get(dpid).keySet()) {
            OFFlowMod newFlowMod = entriesToAdd.get(dpid).get(entry);
            OFFlowMod oldFlowMod = entriesFromStorage.get(dpid).get(entry);
            if (oldFlowMod != null) {  // remove any pre-existing rule
                oldFlowMod.setCommand(OFFlowMod.OFPFC_DELETE_STRICT);
                outQueue.add(oldFlowMod);
            }
            if (newFlowMod != null) {
                entriesFromStorage.get(dpid).put(entry, newFlowMod);
                outQueue.add(newFlowMod);
                entry2dpid.put(entry, dpid);
            } else {
                entriesFromStorage.get(dpid).remove(entry);
                entry2dpid.remove(entry);
            }
        }
        
        writeOFMessagesToSwitch(HexString.toLong(dpid), outQueue);
    }
}
 
开发者ID:vishalshubham,项目名称:Multipath-Hedera-system-in-Floodlight-controller,代码行数:44,代码来源:StaticFlowEntryPusher.java

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

示例15: rowsModified

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
@Override
public void rowsModified(String tableName, Set<Object> rowKeys) {
    // This handles both rowInsert() and rowUpdate()
    log.debug("Modifying Table {}", tableName);
    HashMap<String, Map<String, OFFlowMod>> entriesToAdd = 
        new HashMap<String, Map<String, OFFlowMod>>();
    // build up list of what was added 
    for (Object key: rowKeys) {
        IResultSet resultSet = storageSource.getRow(tableName, key);
        Iterator<IResultSet> it = resultSet.iterator();
        while (it.hasNext()) {
            Map<String, Object> row = it.next().getRow();
            parseRow(row, entriesToAdd);
        }
    }
    // batch updates by switch and blast them out
    for (String dpid : entriesToAdd.keySet()) {
        if (!entriesFromStorage.containsKey(dpid))
            entriesFromStorage.put(dpid, new HashMap<String, OFFlowMod>());
        
        List<OFMessage> outQueue = new ArrayList<OFMessage>();
        for(String entry : entriesToAdd.get(dpid).keySet()) {
            OFFlowMod newFlowMod = entriesToAdd.get(dpid).get(entry);
            //OFFlowMod oldFlowMod = entriesFromStorage.get(dpid).get(entry);
            OFFlowMod oldFlowMod = null;
            String dpidOldFlowMod = entry2dpid.get(entry);
            if (dpidOldFlowMod != null) {
                oldFlowMod = entriesFromStorage.get(dpidOldFlowMod).remove(entry);
            }
            if (oldFlowMod != null && newFlowMod != null) {  
                // set the new flow mod to modify a pre-existing rule if these fields match
                if(oldFlowMod.getMatch().equals(newFlowMod.getMatch())
                        && oldFlowMod.getCookie() == newFlowMod.getCookie()
                        && oldFlowMod.getPriority() == newFlowMod.getPriority()){
                    newFlowMod.setCommand(OFFlowMod.OFPFC_MODIFY_STRICT);
                // if they don't match delete the old flow 
                } else{
                    oldFlowMod.setCommand(OFFlowMod.OFPFC_DELETE_STRICT);
                    if (dpidOldFlowMod.equals(dpid)) {
                        outQueue.add(oldFlowMod);
                    } else {
                        writeOFMessageToSwitch(HexString.toLong(dpidOldFlowMod), oldFlowMod);
                    }
                }
            }
            // write the new flow 
            if (newFlowMod != null) {
                entriesFromStorage.get(dpid).put(entry, newFlowMod);
                outQueue.add(newFlowMod);
                entry2dpid.put(entry, dpid);
            } else {
                entriesFromStorage.get(dpid).remove(entry);
                entry2dpid.remove(entry);
            }
        }
        writeOFMessagesToSwitch(HexString.toLong(dpid), outQueue);
    }
}
 
开发者ID:opendaylight,项目名称:archived-net-virt-platform,代码行数:59,代码来源:StaticFlowEntryPusher.java


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