Examples of OFFlowMod


Examples of org.openflow.protocol.OFFlowMod

        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) mockFloodlightProvider.getOFMessageFactory().
                    getMessage(OFType.FLOW_MOD);
        fm1.setIdleTimeout((short)5)
            .setMatch(match.clone()
                    .setWildcards(expected_wildcards))
            .setActions(actions)
            .setBufferId(OFPacketOut.BUFFER_ID_NONE)
            .setCookie(2L << 52)
View Full Code Here

Examples of org.openflow.protocol.OFFlowMod

        assertEquals(true, writeCapture.hasCaptured());
        assertEquals(TotalTestRules, writeCapture.getValues().size());

        // Order assumes how things are stored in hash bucket;
        // should be fixed because OFMessage.hashCode() is deterministic
        OFFlowMod firstFlowMod = (OFFlowMod) writeCapture.getValues().get(2);
        verifyFlowMod(firstFlowMod, FlowMod1);
        OFFlowMod secondFlowMod = (OFFlowMod) writeCapture.getValues().get(1);
        verifyFlowMod(secondFlowMod, FlowMod2);
        OFFlowMod thirdFlowMod = (OFFlowMod) writeCapture.getValues().get(0);
        verifyFlowMod(thirdFlowMod, FlowMod3);

        writeCapture.reset();
        contextCapture.reset();


        // delete two rules and verify they've been removed
        // this should invoke staticFlowPusher.rowsDeleted()
        storage.deleteRow(StaticFlowEntryPusher.TABLE_NAME, "TestRule1");
        storage.deleteRow(StaticFlowEntryPusher.TABLE_NAME, "TestRule2");

        assertEquals(1, staticFlowEntryPusher.countEntries());
        assertEquals(2, writeCapture.getValues().size());

        OFFlowMod firstDelete = (OFFlowMod) writeCapture.getValues().get(0);
        FlowMod1.setCommand(OFFlowMod.OFPFC_DELETE_STRICT);
        verifyFlowMod(firstDelete, FlowMod1);

        OFFlowMod secondDelete = (OFFlowMod) writeCapture.getValues().get(1);
        FlowMod2.setCommand(OFFlowMod.OFPFC_DELETE_STRICT);
        verifyFlowMod(secondDelete, FlowMod2);

        // add rules back to make sure that staticFlowPusher.rowsInserted() works
        writeCapture.reset();
        FlowMod2.setCommand(OFFlowMod.OFPFC_ADD);
        storage.insertRow(StaticFlowEntryPusher.TABLE_NAME, TestRule2);
        assertEquals(2, staticFlowEntryPusher.countEntries());
        assertEquals(1, writeCaptureList.getValues().size());
        List<OFMessage> outList =
            writeCaptureList.getValues().get(0);
        assertEquals(1, outList.size());
        OFFlowMod firstAdd = (OFFlowMod) outList.get(0);
        verifyFlowMod(firstAdd, FlowMod2);
        writeCapture.reset();
        contextCapture.reset();
        writeCaptureList.reset();

        // now try an overwriting update, calling staticFlowPusher.rowUpdated()
        TestRule3.put(COLUMN_DL_VLAN, 333);
        storage.updateRow(StaticFlowEntryPusher.TABLE_NAME, TestRule3);
        assertEquals(2, staticFlowEntryPusher.countEntries());
        assertEquals(1, writeCaptureList.getValues().size());

        outList = writeCaptureList.getValues().get(0);
        assertEquals(2, outList.size());
        OFFlowMod removeFlowMod = (OFFlowMod) outList.get(0);
        FlowMod3.setCommand(OFFlowMod.OFPFC_DELETE_STRICT);
        verifyFlowMod(removeFlowMod, FlowMod3);
        FlowMod3.setCommand(OFFlowMod.OFPFC_ADD);
        FlowMod3.getMatch().fromString("dl_dst=00:20:30:40:50:60,dl_vlan=333");
        OFFlowMod updateFlowMod = (OFFlowMod) outList.get(1);
        verifyFlowMod(updateFlowMod, FlowMod3);
        writeCaptureList.reset();

        // now try an action modifying update, calling staticFlowPusher.rowUpdated()
        TestRule3.put(COLUMN_ACTIONS, "output=controller,strip-vlan"); // added strip-vlan
        storage.updateRow(StaticFlowEntryPusher.TABLE_NAME, TestRule3);
        assertEquals(2, staticFlowEntryPusher.countEntries());
        assertEquals(1, writeCaptureList.getValues().size());

        outList = writeCaptureList.getValues().get(0);
        assertEquals(1, outList.size());
        OFFlowMod modifyFlowMod = (OFFlowMod) outList.get(0);
        FlowMod3.setCommand(OFFlowMod.OFPFC_MODIFY_STRICT);
        List<OFAction> modifiedActions = FlowMod3.getActions();
        modifiedActions.add(new OFActionStripVirtualLan()); // add the new action to what we should expect
        FlowMod3.setActions(modifiedActions);
        FlowMod3.setLengthU(OFFlowMod.MINIMUM_LENGTH + 16); // accommodate the addition of new actions
View Full Code Here

Examples of org.openflow.protocol.OFFlowMod

        //    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 });
        }
View Full Code Here

Examples of org.openflow.protocol.OFFlowMod

            Map<String, OFFlowMod> entries = entriesFromStorage.get(stringId);
            List<String> sortedList = new ArrayList<String>(entries.keySet());
            // weird that Collections.sort() returns void
            Collections.sort( sortedList, new FlowModSorter(stringId));
            for (String entryName : sortedList) {
                OFFlowMod flowMod = entries.get(entryName);
                if (flowMod != null) {
                    if (log.isDebugEnabled()) {
                        log.debug("Pushing static entry {} for {}", stringId, entryName);
                    }
                    writeFlowModToSwitch(sw, flowMod);
View Full Code Here

Examples of org.openflow.protocol.OFFlowMod

        String switchName = null;
        String entryName = null;

        StringBuffer matchString = new StringBuffer();

        OFFlowMod flowMod = (OFFlowMod) floodlightProvider.getOFMessageFactory()
                .getMessage(OFType.FLOW_MOD);

        if (!row.containsKey(COLUMN_SWITCH) || !row.containsKey(COLUMN_NAME)) {
            log.debug(
                    "skipping entry with missing required 'switch' or 'name' entry: {}",
                    row);
            return;
        }
        // most error checking done with ClassCastException
        try {
            // first, snag the required entries, for debugging info
            switchName = (String) row.get(COLUMN_SWITCH);
            entryName = (String) row.get(COLUMN_NAME);
            if (!entries.containsKey(switchName))
                entries.put(switchName, new HashMap<String, OFFlowMod>());
            StaticFlowEntries.initDefaultFlowMod(flowMod, entryName);

            for (String key : row.keySet()) {
                if (row.get(key) == null)
                    continue;
                if (key.equals(COLUMN_SWITCH) || key.equals(COLUMN_NAME)
                        || key.equals("id"))
                    continue; // already handled
                // explicitly ignore timeouts and wildcards
                if (key.equals(COLUMN_HARD_TIMEOUT) || key.equals(COLUMN_IDLE_TIMEOUT) ||
                        key.equals(COLUMN_WILDCARD))
                    continue;
                if (key.equals(COLUMN_ACTIVE)) {
                    if  (!Boolean.valueOf((String) row.get(COLUMN_ACTIVE))) {
                        log.debug("skipping inactive entry {} for switch {}",
                                entryName, switchName);
                        entries.get(switchName).put(entryName, null)// mark this an inactive
                        return;
                    }
                } else if (key.equals(COLUMN_ACTIONS)){
                    StaticFlowEntries.parseActionString(flowMod, (String) row.get(COLUMN_ACTIONS), log);
                } else if (key.equals(COLUMN_COOKIE)) {
                    flowMod.setCookie(
                            StaticFlowEntries.computeEntryCookie(flowMod,
                                    Integer.valueOf((String) row.get(COLUMN_COOKIE)),
                                    entryName));
                } else if (key.equals(COLUMN_PRIORITY)) {
                    flowMod.setPriority(U16.t(Integer.valueOf((String) row.get(COLUMN_PRIORITY))));
                } else { // the rest of the keys are for OFMatch().fromString()
                    if (matchString.length() > 0)
                        matchString.append(",");
                    matchString.append(key + "=" + row.get(key).toString());
                }
            }
        } catch (ClassCastException e) {
            if (entryName != null && switchName != null) {
                log.warn(
                        "Skipping entry {} on switch {} with bad data : "
                                + e.getMessage(), entryName, switchName);
            } else {
                log.warn("Skipping entry with bad data: {} :: {} ",
                        e.getMessage(), e.getStackTrace());
            }
        }

        OFMatch ofMatch = new OFMatch();
        String match = matchString.toString();
        try {
            ofMatch.fromString(match);
        } catch (IllegalArgumentException e) {
            log.debug(
                    "ignoring flow entry {} on switch {} with illegal OFMatch() key: "
                            + match, entryName, switchName);
            return;
        }
        flowMod.setMatch(ofMatch);

        entries.get(switchName).put(entryName, flowMod);
    }
View Full Code Here

Examples of org.openflow.protocol.OFFlowMod

            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);
                        }
View Full Code Here

Examples of org.openflow.protocol.OFFlowMod

        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 {
View Full Code Here

Examples of org.openflow.protocol.OFFlowMod

        public FlowModSorter(String dpid) {
            this.dpid = dpid;
        }
        @Override
        public int compare(String o1, String o2) {
            OFFlowMod f1 = entriesFromStorage.get(dpid).get(o1);
            OFFlowMod f2 = entriesFromStorage.get(dpid).get(o2);
            if (f1 == null || f2 == null) // sort active=false flows by key
                return o1.compareTo(o2);
            return U16.f(f1.getPriority()) - U16.f(f2.getPriority());
        }
View Full Code Here

Examples of org.openflow.protocol.OFFlowMod

        controller.handleMessage(sw, pi, null);
        verify(test1);
        verify(test2);
        verify(test3);

        OFFlowMod fm = (OFFlowMod)
                BasicFactory.getInstance().getMessage(OFType.FLOW_MOD);

        //------------------
        // Test FlowMod handling: all listeners return CONTINUE
        reset(test1, test2, test3);
View Full Code Here

Examples of org.openflow.protocol.OFFlowMod

        wildCard = wildCard ^ OFMatch.OFPFW_TP_DST;

      }
    }
      ofMatch.setWildcards(wildCard);
      OFFlowMod oFFlowMod = new OFFlowMod();
      oFFlowMod.setType(OFType.FLOW_MOD);
      oFFlowMod.setMatch(ofMatch);
      oFFlowMod.setCommand(OFFlowMod.OFPFC_ADD);
      oFFlowMod.setBufferId(-1);
      oFFlowMod
          .setPriority(Short.parseShort(cliArguments.get("priority")));
      oFFlowMod.setIdleTimeout((Short.parseShort( cliArguments.get("idle_timeout"))));
      oFFlowMod.setHardTimeout((Short.parseShort(cliArguments.get("hard_timeout"))));

     
     
      ArrayList<OFAction> flowActions = new ArrayList<OFAction>();
     
      if(cliArguments.get("actions") != null){
      Short  actions = Short.parseShort(cliArguments.get("actions"));
      OFActionOutput actionOutput = new OFActionOutput();
      actionOutput.setPort(actions);
     
     
      flowActions.add(actionOutput);
      oFFlowMod.setActions(flowActions);
      }
     
      IOFSwitch sw = ibeaconProvider.getSwitches().get(
          HexString.toLong(cliArguments.get("switch")));
      try {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.