本文整理汇总了Java中org.openflow.protocol.OFFlowMod.setActions方法的典型用法代码示例。如果您正苦于以下问题:Java OFFlowMod.setActions方法的具体用法?Java OFFlowMod.setActions怎么用?Java OFFlowMod.setActions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openflow.protocol.OFFlowMod
的用法示例。
在下文中一共展示了OFFlowMod.setActions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testIsFlowModAllowedSimple
import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
@Test
public void testIsFlowModAllowedSimple(){
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);
List<OFAction> actions = new ArrayList<OFAction>();
OFActionVirtualLanIdentifier setVid = new OFActionVirtualLanIdentifier();
setVid.setVirtualLanIdentifier((short)102);
OFActionOutput output = new OFActionOutput();
output.setPort((short)2);
actions.add(setVid);
actions.add(output);
flow.setActions(actions);
List <OFFlowMod> flows = slicer.allowedFlows(flow);
assertTrue("flows is the right size", flows.size() == 1);
assertEquals("flow was allowed and matches", flow, flows.get(0));
}
示例2: 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);
}
示例3: mod
import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Modifies particular flow rule in the switch {@link IOFSwitch}
* @param sw
* @param floodlightProvider
* @param cntx
* @param dcIP
* @param dcMask
* @param outPort
*/
public static void mod(IOFSwitch sw, IFloodlightProviderService floodlightProvider, FloodlightContext cntx, String dcIP, int dcMask, short outPort) {
logger.debug("mod(IOFSwitch,IFloodlightProviderService,FloodlightContext,String,int,short) begin");
OFFlowMod flowMod = (OFFlowMod) floodlightProvider.getOFMessageFactory().getMessage(OFType.FLOW_MOD);
OFMatch mTo = new OFMatch();
String match = "dl_type=0x800,nw_dst=" + dcIP + "/" + Integer.toString(dcMask);
mTo.fromString(match);
flowMod.setMatch(mTo);
flowMod.setCommand(OFFlowMod.OFPFC_MODIFY_STRICT); //OFPFC_MODIFY
flowMod.setIdleTimeout((short) 0);
flowMod.setHardTimeout((short) 0);
flowMod.setPriority((short) 100);
flowMod.setBufferId(OFPacketOut.BUFFER_ID_NONE);
flowMod.setFlags((short) 1);
List<OFAction> actions = new ArrayList<>();
actions.add(new OFActionOutput().setPort(outPort));
flowMod.setActions(actions);
flowMod.setLengthU(OFFlowMod.MINIMUM_LENGTH + OFActionOutput.MINIMUM_LENGTH);
logger.debug("Modyfing to rule {}", flowMod.toString());
try {
sw.write(flowMod, cntx);
sw.flush();
logger.debug(String.format("Flow rule (out port %d) added to switch %s", outPort, sw.getStringId()));
} catch (IOException ex) {
logger.error(String.format("Error while modyfing flow rule (out port %d) to switch %s", outPort, sw.getStringId()), ex);
}
logger.debug("mod(IOFSwitch,IFloodlightProviderService,FloodlightContext,String,int,short) end");
}
示例4: 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();
}
}
示例5: buildFlowMod
import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* buildFlowMod - builds a FlowMod based on a flowStat
* @param flowStat
* @return OFFlowMod
*/
private OFFlowMod buildFlowMod(OFFlowStatisticsReply flowStat){
OFFlowMod flowMod = new OFFlowMod();
flowMod.setMatch(flowStat.getMatch().clone());
flowMod.setActions(flowStat.getActions());
flowMod.setPriority(flowStat.getPriority());
flowMod.setCookie(flowStat.getCookie());
flowMod.setIdleTimeout(flowStat.getIdleTimeout());
flowMod.setHardTimeout(flowStat.getHardTimeout());
return flowMod;
}
示例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);
}
}
示例7: parseActionString
import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Parses OFFlowMod actions from strings.
* @param flowMod The OFFlowMod to set the actions for
* @param actionstr The string containing all the actions
* @param log A logger to log for errors.
*/
public static void parseActionString(OFFlowMod flowMod, String actionstr, Logger log) {
List<OFAction> actions = new LinkedList<OFAction>();
int actionsLength = 0;
if (actionstr != null) {
actionstr = actionstr.toLowerCase();
for (String subaction : actionstr.split(",")) {
String action = subaction.split("[=:]")[0];
SubActionStruct subaction_struct = null;
if (action.equals("output")) {
subaction_struct = decode_output(subaction, log);
}
else if (action.equals("enqueue")) {
subaction_struct = decode_enqueue(subaction, log);
}
else if (action.equals("strip-vlan")) {
subaction_struct = decode_strip_vlan(subaction, log);
}
else if (action.equals("set-vlan-id")) {
subaction_struct = decode_set_vlan_id(subaction, log);
}
else if (action.equals("set-vlan-priority")) {
subaction_struct = decode_set_vlan_priority(subaction, log);
}
else if (action.equals("set-src-mac")) {
subaction_struct = decode_set_src_mac(subaction, log);
}
else if (action.equals("set-dst-mac")) {
subaction_struct = decode_set_dst_mac(subaction, log);
}
else if (action.equals("set-tos-bits")) {
subaction_struct = decode_set_tos_bits(subaction, log);
}
else if (action.equals("set-src-ip")) {
subaction_struct = decode_set_src_ip(subaction, log);
}
else if (action.equals("set-dst-ip")) {
subaction_struct = decode_set_dst_ip(subaction, log);
}
else if (action.equals("set-src-port")) {
subaction_struct = decode_set_src_port(subaction, log);
}
else if (action.equals("set-dst-port")) {
subaction_struct = decode_set_dst_port(subaction, log);
}
else {
log.error("Unexpected action '{}', '{}'", action, subaction);
}
if (subaction_struct != null) {
actions.add(subaction_struct.action);
actionsLength += subaction_struct.len;
}
}
}
log.debug("action {}", actions);
flowMod.setActions(actions);
flowMod.setLengthU(OFFlowMod.MINIMUM_LENGTH + actionsLength);
}
示例8: parseActionString
import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
/**
* Parses OFFlowMod actions from strings.
* @param flowMod The OFFlowMod to set the actions for
* @param actionstr The string containing all the actions
* @param log A logger to log for errors.
*/
@LogMessageDoc(level="ERROR",
message="Unexpected action '{action}', '{subaction}'",
explanation="A static flow entry contained an invalid action",
recommendation=LogMessageDoc.REPORT_CONTROLLER_BUG)
public static void parseActionString(OFFlowMod flowMod, String actionstr, Logger log) {
List<OFAction> actions = new LinkedList<OFAction>();
int actionsLength = 0;
if (actionstr != null) {
actionstr = actionstr.toLowerCase();
for (String subaction : actionstr.split(",")) {
String action = subaction.split("[=:]")[0];
SubActionStruct subaction_struct = null;
if (action.equals("output")) {
subaction_struct = StaticFlowEntries.decode_output(subaction, log);
}
else if (action.equals("enqueue")) {
subaction_struct = decode_enqueue(subaction, log);
}
else if (action.equals("strip-vlan")) {
subaction_struct = decode_strip_vlan(subaction, log);
}
else if (action.equals("set-vlan-id")) {
subaction_struct = decode_set_vlan_id(subaction, log);
}
else if (action.equals("set-vlan-priority")) {
subaction_struct = decode_set_vlan_priority(subaction, log);
}
else if (action.equals("set-src-mac")) {
subaction_struct = decode_set_src_mac(subaction, log);
}
else if (action.equals("set-dst-mac")) {
subaction_struct = decode_set_dst_mac(subaction, log);
}
else if (action.equals("set-tos-bits")) {
subaction_struct = decode_set_tos_bits(subaction, log);
}
else if (action.equals("set-src-ip")) {
subaction_struct = decode_set_src_ip(subaction, log);
}
else if (action.equals("set-dst-ip")) {
subaction_struct = decode_set_dst_ip(subaction, log);
}
else if (action.equals("set-src-port")) {
subaction_struct = decode_set_src_port(subaction, log);
}
else if (action.equals("set-dst-port")) {
subaction_struct = decode_set_dst_port(subaction, log);
}
else {
log.error("Unexpected action '{}', '{}'", action, subaction);
}
if (subaction_struct != null) {
actions.add(subaction_struct.action);
actionsLength += subaction_struct.len;
}
}
}
log.debug("action {}", actions);
flowMod.setActions(actions);
flowMod.setLengthU(OFFlowMod.MINIMUM_LENGTH + actionsLength);
}
示例9: 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
示例10: 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);
}
}
示例11: 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);
}
示例12: testBrokenStats
import org.openflow.protocol.OFFlowMod; //导入方法依赖的package包/类
@Test
public void testBrokenStats(){
List<HashMap<Long, Slicer>> tmp = new ArrayList<HashMap<Long, Slicer>>();
HashMap<Long, Slicer> tmpMap = new HashMap<Long, Slicer>();
tmpMap.put(sw.getId(), slicer);
tmp.add(tmpMap);
tmpMap = new HashMap<Long, Slicer>();
tmpMap.put(sw.getId(), managedSlicer);
tmp.add(tmpMap);
tmpMap = new HashMap<Long, Slicer>();
tmpMap.put(sw.getId(), slicerExpanded);
tmp.add(tmpMap);
tmpMap = new HashMap<Long, Slicer>();
tmpMap.put(sw.getId(), managedExpandedSlicer);
tmp.add(tmpMap);
Proxy proxy = createMock(Proxy.class);
expect(proxy.getSlicer()).andReturn(managedExpandedSlicer).anyTimes();
proxy.setFlowCount(EasyMock.anyInt());
EasyMock.expectLastCall().anyTimes();
EasyMock.replay(proxy);
fsfw = createMock(FlowSpaceFirewall.class);
List<IOFSwitch> switches = new ArrayList<IOFSwitch>();
switches.add(sw);
expect(fsfw.getSlices()).andReturn(tmp).anyTimes();
expect(fsfw.getSwitches()).andReturn(switches).anyTimes();
expect(fsfw.getProxy(EasyMock.anyLong(), EasyMock.anyObject(String.class))).andReturn(proxy).anyTimes();
HashMap<Long, Slicer> sliceMap = new HashMap<Long, Slicer>();
sliceMap.put(sw.getId(), managedExpandedSlicer);
expect(fsfw.getSlice(EasyMock.anyObject(String.class))).andReturn(sliceMap).anyTimes();
EasyMock.replay(fsfw);
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<OFStatistics>bustedExpandedManagedStats = new ArrayList<OFStatistics>(expandedManagedStats);
OFFlowStatisticsReply stat = (OFFlowStatisticsReply) bustedExpandedManagedStats.get(5);
OFActionVirtualLanIdentifier set_vlan_vid = new OFActionVirtualLanIdentifier();
set_vlan_vid.setVirtualLanIdentifier((short)500);
List<OFAction> newActs = new ArrayList<OFAction>();
newActs.add(set_vlan_vid);
newActs.add(output);
stat.setActions(newActs);
bustedExpandedManagedStats.set(5, stat);
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 returned ok", slicedStats);
assertEquals("Sliced stats", 5, slicedStats.size());
log.error(slicedStats.get(0).toString());
OFFlowStatisticsReply flowStat = (OFFlowStatisticsReply) slicedStats.get(0);
assertEquals("flowStat byte count is correct", 1L,flowStat.getByteCount());
assertEquals("flowStat packet count is correct", 1L,flowStat.getPacketCount());
}
示例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");
}
示例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);
}
示例15: 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);
}
}