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


Java OFFlowMod.setMatch方法代码示例

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


在下文中一共展示了OFFlowMod.setMatch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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();
			}
		}
	}
}
 
开发者ID:GlobalNOC,项目名称:FlowSpaceFirewall,代码行数:27,代码来源:FlowStatCache.java

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

示例3: testIsFlowModAllowedExpansions

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
 * tests isFlowModAllowed for expansions
 */
@Test 
public void testIsFlowModAllowedExpansions(){
	List<OFAction> actions = new ArrayList<OFAction>();
	OFActionOutput output = new OFActionOutput();
	OFActionVirtualLanIdentifier setVid = new OFActionVirtualLanIdentifier();
	setVid.setVirtualLanIdentifier((short)100);
	actions.add(setVid);
	output.setPort((short)1);
	actions.add(output);
	
	OFFlowMod flow = new OFFlowMod();
	OFMatch match = new OFMatch();
	match.setInputPort((short)0);
	match.setDataLayerVirtualLan((short)1000);
	match.setWildcards(match.getWildcardObj().matchOn(Flag.DL_VLAN));
	flow.setMatch(match);
	flow.setActions(actions);
	List<OFFlowMod>flows = slicer.allowedFlows(flow);
	assertTrue("flow was denied",flows.size() != 0);
	assertTrue("Flow Expansion worked", flows.size() == 5);

	PortConfig tmpPConfig = new PortConfig();
	tmpPConfig.setPortName("foo4");
	VLANRange range = new VLANRange();
	range.setVlanAvail((short)100, true);
	range.setVlanAvail((short)1000, true);
	tmpPConfig.setVLANRange(range);
	slicer.setPortConfig("foo4", tmpPConfig);
	

	flows = slicer.allowedFlows(flow);
	assertTrue("flow was denied",flows.size() != 0);
	assertTrue("Flow Expansion worked, and then we detected it was total number of ports so changed to just 1, got " + flows.size(), flows.size() == 1);
	
}
 
开发者ID:GlobalNOC,项目名称:FlowSpaceFirewall,代码行数:39,代码来源:VLANSlicerTest.java

示例4: processOFStatisticsReply

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
@Override
void processOFStatisticsReply(final SwitchChannelHandler h,
        final OFStatisticsReply m) {
    // Read description, if it has been updated
    final OVXDescriptionStatistics description = new OVXDescriptionStatistics();
    final ChannelBuffer data = ChannelBuffers.buffer(description
            .getLength());
    final OFStatistics f = m.getFirstStatistics();
    f.writeTo(data);
    description.readFrom(data);
    OFFlowMod fm = new OFFlowMod();
    fm.setCommand(OFFlowMod.OFPFC_DELETE);
    fm.setMatch(new OFMatch());
    h.channel.write(Collections.singletonList(fm));
    h.sw = new PhysicalSwitch(h.featuresReply.getDatapathId());
    // set switch information
    // set features reply and channel first so we have a DPID and
    // channel info.
    h.sw.setFeaturesReply(h.featuresReply);
    h.sw.setDescriptionStats(description);
    h.sw.setConnected(true);
    h.sw.setChannel(h.channel);

    for (final OFPortStatus ps : h.pendingPortStatusMsg) {
        this.handlePortStatusMessage(h, ps);
    }
    h.pendingPortStatusMsg.clear();
    h.sw.boot();
    h.setState(ACTIVE);
}
 
开发者ID:CoVisor,项目名称:CoVisor,代码行数:31,代码来源:SwitchChannelHandler.java

示例5: 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);
        }
}
 
开发者ID:daniel666,项目名称:multicastSDN,代码行数:39,代码来源:IGMPCapture.java

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

示例7: testExpandedFlowStats

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
@Test
public void testExpandedFlowStats(){
	cache = new FlowStatCache(fsfw);
	
	OFFlowMod mod = new OFFlowMod();
	OFMatch match = new OFMatch();
	match.setDataLayerVirtualLan((short)300);
	match.setWildcards(match.getWildcardObj().matchOn(Flag.DL_VLAN));
	mod.setMatch(match);
	List<OFAction> actions = new ArrayList<OFAction>();
	OFActionOutput output = new OFActionOutput();
	output.setPort((short)65533);
	actions.add(output);
	mod.setActions(actions);
	
	List<OFFlowMod> mods = slicerExpanded.allowedFlows(mod);
	cache.addFlowMod(sw.getId(), slicerExpanded.getSliceName(), mod, mods);
	log.error("Sending: " + expandedStats.size() + " flow stats!");
	cache.setFlowCache(sw.getId(), expandedStats);
	List<OFStatistics> slicedStats = cache.getSlicedFlowStats(sw.getId(), slicerExpanded.getSliceName());	
	assertNotNull("Sliced Stats with no allowed stats returend ok", slicedStats);
	assertEquals("Sliced stats", 6, slicedStats.size());
	log.error(slicedStats.get(0).toString());
	OFFlowStatisticsReply flowStat = (OFFlowStatisticsReply) slicedStats.get(0);
	assertEquals("flowStat byte count is correct", 4L,flowStat.getByteCount());
	assertEquals("flowStat packet count is correct", 4L,flowStat.getPacketCount());
}
 
开发者ID:GlobalNOC,项目名称:FlowSpaceFirewall,代码行数:28,代码来源:FlowStatSlicerTest.java

示例8: testExpandedFlowStatsManaged

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
@Test
public void testExpandedFlowStatsManaged(){
	cache = new FlowStatCache(fsfw);
	
	
	OFFlowMod mod = new OFFlowMod();
	OFMatch match = new OFMatch();

	match.setWildcards(match.getWildcardObj().matchOn(Flag.DL_DST));
	match.setDataLayerDestination("78:2B:CB:48:FF:73");


	mod.setMatch(match);
	List<OFAction> actions = new ArrayList<OFAction>();
	OFActionOutput output = new OFActionOutput();
	output.setPort((short)1);
	actions.add(output);
	mod.setActions(actions);
	mod.setLength((short)(OFFlowMod.MINIMUM_LENGTH + output.getLength()));
	
	List<OFFlowMod> mods = managedExpandedSlicer.managedFlows(mod);
	assertEquals("Proper number of total flow mods", 4,mods.size());
	cache.addFlowMod(sw.getId(), managedExpandedSlicer.getSliceName(), mod, mods);
	cache.setFlowCache(sw.getId(), expandedManagedStats);
	List<OFStatistics> slicedStats = cache.getSlicedFlowStats(sw.getId(), managedExpandedSlicer.getSliceName());	
	assertNotNull("Sliced Stats with no allowed stats returend ok", slicedStats);
	for(OFStatistics stat : slicedStats){
		log.error(stat.toString());
	}
	assertEquals("Sliced stats", 6, slicedStats.size());
	log.error(slicedStats.get(0).toString());
	OFFlowStatisticsReply flowStat = (OFFlowStatisticsReply) slicedStats.get(0);
	assertEquals("flowStat byte count is correct", 4L,flowStat.getByteCount());
	assertEquals("flowStat packet count is correct", 4L,flowStat.getPacketCount());
}
 
开发者ID:GlobalNOC,项目名称:FlowSpaceFirewall,代码行数:36,代码来源:FlowStatSlicerTest.java

示例9: testIsFlowModALLAllowedExpansions

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
 * tests isFlowModAllowed for expansions
 */
@Test 
public void testIsFlowModALLAllowedExpansions(){
	List<OFAction> actions = new ArrayList<OFAction>();
	OFActionOutput output = new OFActionOutput();
	OFActionVirtualLanIdentifier setVid = new OFActionVirtualLanIdentifier();
	setVid.setVirtualLanIdentifier((short)1000);
	actions.add(setVid);
	output.setPort(OFPort.OFPP_ALL.getValue());
	actions.add(output);
	
	PortConfig pConfig5 = new PortConfig();
	pConfig5.setPortName("foo5");
	VLANRange range = new VLANRange();
	range.setVlanAvail((short)104, true);
	range.setVlanAvail((short)1000, true);
	pConfig5.setVLANRange(range);
	slicer.setPortConfig("foo5", pConfig5);
	
	OFFlowMod flow = new OFFlowMod();
	OFMatch match = new OFMatch();
	match.setInputPort((short)1);
	match.setDataLayerVirtualLan((short)1000);
	match.setWildcards(match.getWildcardObj().matchOn(Flag.DL_VLAN));
	match.setWildcards(match.getWildcardObj().matchOn(Flag.IN_PORT));
	flow.setMatch(match);
	flow.setActions(actions);
	
	List<OFFlowMod>flows = slicer.allowedFlows(flow);
	
	assertTrue("flow was denied",flows.size() != 0);
	assertTrue("Flow Expansion worked had a size of " + flows.size(), flows.size() == 1);
	
	OFFlowMod expanded = flows.get(0);
	assertTrue("Correct number of actions", expanded.getActions().size() == 5);
	
}
 
开发者ID:GlobalNOC,项目名称:FlowSpaceFirewall,代码行数:40,代码来源:VLANSlicerTest.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: 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

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

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

示例14: testIsFlowModALLAllowedWildcardExpansions

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
 * tests isFlowModAllowed for expansions
 */
@Test 
public void testIsFlowModALLAllowedWildcardExpansions(){
	List<OFAction> actions = new ArrayList<OFAction>();
	OFActionOutput output = new OFActionOutput();
	OFActionVirtualLanIdentifier setVid = new OFActionVirtualLanIdentifier();
	setVid.setVirtualLanIdentifier((short)1000);
	actions.add(setVid);
	output.setPort(OFPort.OFPP_ALL.getValue());
	actions.add(output);
	
	PortConfig pConfig5 = new PortConfig();
	pConfig5.setPortName("foo5");
	VLANRange range = new VLANRange();
	range.setVlanAvail((short)104, true);
	range.setVlanAvail((short)1000, true);
	pConfig5.setVLANRange(range);
	slicer.setPortConfig("foo5", pConfig5);
	
	PortConfig pConfig4 = new PortConfig();
	pConfig4.setPortName("foo4");
	range = new VLANRange();
	range.setVlanAvail((short)104, true);
	range.setVlanAvail((short)1000, true);
	pConfig4.setVLANRange(range);
	slicer.setPortConfig("foo4", pConfig4);
	
	OFFlowMod flow = new OFFlowMod();
	OFMatch match = new OFMatch();
	match.setInputPort((short)0);
	match.setDataLayerVirtualLan((short)1000);
	match.setWildcards(match.getWildcardObj().matchOn(Flag.DL_VLAN));
	flow.setMatch(match);
	flow.setActions(actions);
	
	List<OFFlowMod>flows = slicer.allowedFlows(flow);
	
	assertTrue("flow was denied",flows.size() != 0);
	assertTrue("Flow Expansion worked had a size of " + flows.size(), flows.size() == 1);
	
	OFFlowMod expanded = flows.get(0);
	assertTrue("Correct number of actions expected 5 got " + expanded.getActions().size(), expanded.getActions().size() == 2);
	
}
 
开发者ID:GlobalNOC,项目名称:FlowSpaceFirewall,代码行数:47,代码来源:VLANSlicerTest.java

示例15: testManagedFlowMod

import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
@Test
public void testManagedFlowMod(){
	VLANSlicer otherSlicer = new VLANSlicer();
	otherSlicer.setTagManagement(true);
	pConfig = new PortConfig();
	pConfig.setPortName("foo");
	VLANRange range = new VLANRange();
	range.setVlanAvail((short)101,true);
	pConfig.setVLANRange(range);
	otherSlicer.setPortConfig("foo", pConfig);
	
	pConfig2 = new PortConfig();
	pConfig2.setPortName("foo2");
	range = new VLANRange();
	range.setVlanAvail((short)103,true);
	pConfig2.setVLANRange(range);
	otherSlicer.setPortConfig("foo2", pConfig2);

	pConfig3 = new PortConfig();
	pConfig3.setPortName("foo3");
	range = new VLANRange();
	range.setVlanAvail((short)104,true);
	pConfig3.setVLANRange(range);
	otherSlicer.setPortConfig("foo3", pConfig3);
	
	pConfig5 = new PortConfig();
	pConfig5.setPortName("foo5");
	range = new VLANRange();
	range.setVlanAvail((short)106,true);
	pConfig5.setVLANRange(range);
	otherSlicer.setPortConfig("foo5", pConfig5);
	
	pConfig6 = new PortConfig();
	pConfig6.setPortName("foo6");
	range = new VLANRange();
	range.setVlanAvail((short)107,true);
	pConfig6.setVLANRange(range);
	otherSlicer.setPortConfig("foo6", pConfig6);
	
	otherSlicer.setSwitch(sw);
	
	OFFlowMod flowMod = new OFFlowMod();
	OFMatch match = new OFMatch();
	match.setInputPort((short)3);
	match.setWildcards(match.getWildcardObj().matchOn(Flag.IN_PORT));
	flowMod.setMatch(match);
	List<OFAction> actions = new ArrayList<OFAction>();
	OFActionOutput out = new OFActionOutput();
	out.setPort((short)1);
	actions.add(out);
	flowMod.setActions(actions);
	flowMod.setLength((short)(OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH));
	List<OFFlowMod> managedFlows = otherSlicer.managedFlows(flowMod);
	assertTrue(managedFlows.size() == 1);
	OFFlowMod processedFlow = managedFlows.get(0);
	assertTrue(processedFlow.getMatch().getDataLayerVirtualLan() == 104);
	List<OFAction> processedActions = processedFlow.getActions();
	assertTrue(processedActions.size() == 2);
	assertTrue(processedActions.get(0).getType() == OFActionType.SET_VLAN_ID);
	OFActionVirtualLanIdentifier set_vlan_vid = (OFActionVirtualLanIdentifier)processedActions.get(0);
	assertTrue(set_vlan_vid.getVirtualLanIdentifier() == 101);
	
	actions = new ArrayList<OFAction>();
	OFActionVirtualLanIdentifier set_vlan = new OFActionVirtualLanIdentifier();
	set_vlan.setVirtualLanIdentifier((short)100);
	actions.add(set_vlan);
	actions.add(out);
	flowMod.setActions(actions);
	flowMod.setLength((short)(OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH + OFActionVirtualLanIdentifier.MINIMUM_LENGTH));
	managedFlows = otherSlicer.managedFlows(flowMod);
	assertTrue(managedFlows.size() == 0);
	
}
 
开发者ID:GlobalNOC,项目名称:FlowSpaceFirewall,代码行数:74,代码来源:VLANSlicerTest.java


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