本文整理汇总了Java中org.opendaylight.controller.sal.action.Action类的典型用法代码示例。如果您正苦于以下问题:Java Action类的具体用法?Java Action怎么用?Java Action使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Action类属于org.opendaylight.controller.sal.action包,在下文中一共展示了Action类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionsFromJson
import org.opendaylight.controller.sal.action.Action; //导入依赖的package包/类
/**
* Create OpenDaylight actions from JSON specifications.
*
* @param node the node to be programmed (required for specifying valid output actions with correct node connectors)
* @param actionsJson JSON array specifying actions
* @return list of created OpenDaylight actions
*/
private List<Action> actionsFromJson(Node node, JSONArray actionsJson) throws JSONException {
List<Action> actions = new LinkedList<Action>();
for (int i = 0; i < actionsJson.length(); i++) {
JSONObject actionJson = actionsJson.getJSONObject(i);
Action action = parseAction(node, actionJson);
if (action == null) {
log.error("Invalid action: " + actionJson.toString());
return null;
} else {
actions.add(action);
}
}
return actions;
}
示例2: testFlowEntries
import org.opendaylight.controller.sal.action.Action; //导入依赖的package包/类
@Test
public void testFlowEntries() {
Flow flow = new Flow();
Match match = new Match();
try {
match.setField(MatchType.NW_DST, InetAddress.getByName("1.1.1.1"));
} catch (UnknownHostException e) {
}
flow.setMatch(match);
Action action = new Drop();
List<Action> actions = new ArrayList<Action>();
actions.add(action);
flow.setActions(actions);
Node node = NodeCreator.createOFNode(1L);
FlowEntry fe = new FlowEntry("g1", "f1", flow, node);
Status stat = manager.installFlowEntry(fe);
// OF plugin is not there in integration testing mode
Assert.assertTrue(stat.getCode() == StatusCode.NOSERVICE);
}
示例3: removeOutputPort
import org.opendaylight.controller.sal.action.Action; //导入依赖的package包/类
@Override
public void removeOutputPort(Node node, String flowName, List<NodeConnector> portList) {
for (FlowEntryInstall index : this.nodeFlows.get(node)) {
FlowEntryInstall flow = this.installedSwView.get(index);
if (flow.getFlowName().equals(flowName)) {
FlowEntry currentFlowEntry = flow.getOriginal();
FlowEntry newFlowEntry = currentFlowEntry.clone();
for (NodeConnector dstPort : portList) {
Action action = new Output(dstPort);
newFlowEntry.getFlow().removeAction(action);
}
Status status = modifyEntry(currentFlowEntry, newFlowEntry, false);
if (status.isSuccess()) {
log.info("Ports {} removed from FlowEntry {}", portList, flowName);
} else {
log.warn("Failed to remove ports {} from Flow entry {}. The failure is: {}", portList,
currentFlowEntry.toString(), status.getDescription());
}
return;
}
}
log.warn("Failed to remove ports from Flow {} on Node {}: Entry Not Found", flowName, node);
}
示例4: actionsAreIPv6
import org.opendaylight.controller.sal.action.Action; //导入依赖的package包/类
/**
* Returns true if it finds at least one action which is for IPv6 in the
* list of actions for this Flow
*
* @return
*/
private boolean actionsAreIPv6() {
if (this.actions != null) {
for (Action action : actions) {
switch (action.getType()) {
case SET_NW_SRC:
if (((SetNwSrc) action).getAddress() instanceof Inet6Address) {
return true;
}
break;
case SET_NW_DST:
if (((SetNwDst) action).getAddress() instanceof Inet6Address) {
return true;
}
break;
case SET_DL_TYPE:
if (((SetDlType) action).getDlType() == EtherTypes.IPv6.intValue()) {
return true;
}
break;
default:
}
}
}
return false;
}
示例5: testFlowActions
import org.opendaylight.controller.sal.action.Action; //导入依赖的package包/类
@Test
public void testFlowActions() throws UnknownHostException {
Node node = NodeCreator.createOFNode(55l);
Flow flow = getSampleFlowV6(node);
List<Action> actions = flow.getActions();
actions.add(new Loopback());
Assert.assertTrue(flow.getActions() != actions);
Assert.assertTrue(!flow.getActions().equals(actions));
flow.addAction(new Loopback());
Assert.assertTrue(flow.getActions().equals(actions));
actions.remove(new Loopback());
flow.removeAction(new Loopback());
Assert.assertTrue(flow.getActions().equals(actions));
// Add a malformed action
Assert.assertFalse(flow.addAction(new PushVlan(EtherTypes.CISCOQINQ, 3,
3, 8000)));
}
示例6: flowPortsBelongToContainer
import org.opendaylight.controller.sal.action.Action; //导入依赖的package包/类
/**
* Check whether the ports in the flow match and flow actions for
* the specified node belong to the container
*
* @param container
* @param node
* @param flow
* @return
*/
private boolean flowPortsBelongToContainer(String container, Node node,
Flow flow) {
Match m = flow.getMatch();
if (m.isPresent(MatchType.IN_PORT)) {
NodeConnector inPort = (NodeConnector) m.getField(MatchType.IN_PORT).getValue();
// If the incoming port is specified, check if it belongs to
if (!containerOwnsNodeConnector(container, inPort)) {
return false;
}
}
// If an outgoing port is specified, it must belong to this container
for (Action action : flow.getActions()) {
if (action.getType() == ActionType.OUTPUT) {
NodeConnector outPort = ((Output) action).getPort();
if (!containerOwnsNodeConnector(container, outPort)) {
return false;
}
}
}
return true;
}
示例7: testFlowEntrySet
import org.opendaylight.controller.sal.action.Action; //导入依赖的package包/类
@Test
public void testFlowEntrySet() throws UnknownHostException {
Set<FlowEntry> set = new HashSet<FlowEntry>();
Node node1 = NodeCreator.createOFNode(1L);
Node node2 = NodeCreator.createOFNode(2L);
Node node3 = NodeCreator.createOFNode(3L);
Match match = new Match();
match.setField(MatchType.NW_SRC, InetAddress.getAllByName("1.1.1.1"));
match.setField(MatchType.NW_DST, InetAddress.getAllByName("2.2.2.2"));
match.setField(MatchType.DL_TYPE, EtherTypes.IPv4.shortValue());
List<Action> actionList = new ArrayList<Action>();
// actionList.add(new Drop());
Flow flow = new Flow(match, actionList);
FlowEntry pol1 = new FlowEntry("m1", "same", flow, node1);
FlowEntry pol2 = new FlowEntry("m2", "same", flow, node2);
FlowEntry pol3 = new FlowEntry("m3", "same", flow, node3);
set.add(pol1);
set.add(pol2);
set.add(pol3);
Assert.assertTrue(set.contains(pol1));
Assert.assertTrue(set.contains(pol2));
Assert.assertTrue(set.contains(pol3));
Assert.assertTrue(set.contains(pol1.clone()));
Assert.assertTrue(set.contains(pol2.clone()));
Assert.assertTrue(set.contains(pol3.clone()));
}
示例8: getOutputPort
import org.opendaylight.controller.sal.action.Action; //导入依赖的package包/类
@Override
public NodeConnector getOutputPort(Node node, String flowName) {
for (FlowEntryInstall index : this.nodeFlows.get(node)) {
FlowEntryInstall flow = this.installedSwView.get(index);
if (flow.getFlowName().equals(flowName)) {
for (Action action : flow.getOriginal().getFlow().getActions()) {
if (action.getType() == ActionType.OUTPUT) {
return ((Output) action).getPort();
}
}
}
}
return null;
}
示例9: Flow
import org.opendaylight.controller.sal.action.Action; //导入依赖的package包/类
public Flow(Match match, List<Action> actions) {
if (match.isIPv4() && actionsAreIPv6()) {
try {
throw new Exception("Conflicting Match and Action list");
} catch (Exception e) {
logger.error("", e);
}
} else {
this.match = match;
this.actions = actions;
}
}
示例10: setActions
import org.opendaylight.controller.sal.action.Action; //导入依赖的package包/类
/**
* Set the actions list for this flow If a list is already present, it will
* be replaced with the passed one. During addition, only the valid actions
* will be added It is a no op if the passed actions is null An empty
* actions is a vlaid input
*
* @param actions
*/
public void setActions(List<Action> actions) {
if (actions == null) {
return;
}
this.actions = new ArrayList<Action>(actions.size());
for (Action action : actions) {
if (action.isValid()) {
this.actions.add(action);
}
}
}
示例11: removeAction
import org.opendaylight.controller.sal.action.Action; //导入依赖的package包/类
/**
* remove ALL actions of type actionType from the list of actions of this
* flow
*
* @param actionType
* @return false if an action of that type is present and it fails to remove
* it
*/
public boolean removeAction(ActionType actionType) {
Iterator<Action> actionIter = this.getActions().iterator();
while (actionIter.hasNext()) {
Action action = actionIter.next();
if (action.getType() == actionType) {
if (!this.removeAction(action)) {
return false;
}
}
}
return true;
}
示例12: testFlowEquality
import org.opendaylight.controller.sal.action.Action; //导入依赖的package包/类
@Test
public void testFlowEquality() throws Exception {
Node node = NodeCreator.createOFNode(1055l);
Flow flow1 = getSampleFlowV6(node);
Flow flow2 = getSampleFlowV6(node);
Flow flow3 = getSampleFlow(node);
// Check Match equality
Assert.assertTrue(flow1.getMatch().equals(flow2.getMatch()));
// Check Actions equality
for (int i = 0; i < flow1.getActions().size(); i++) {
Action a = flow1.getActions().get(i);
Action b = flow2.getActions().get(i);
Assert.assertTrue(a != b);
Assert.assertTrue(a.equals(b));
}
Assert.assertTrue(flow1.equals(flow2));
Assert.assertFalse(flow2.equals(flow3));
// Check Flow equality where Flow has null action list (pure match)
List<Action> emptyList = new ArrayList<Action>(1);
Flow x = flow1.clone();
x.setActions(emptyList);
Assert.assertFalse(flow1.equals(x));
flow1.setActions(emptyList);
Assert.assertTrue(flow1.equals(x));
}
示例13: testFlowOnNodeMethods
import org.opendaylight.controller.sal.action.Action; //导入依赖的package包/类
@Test
public void testFlowOnNodeMethods () {
Match match = new Match();
NodeConnector inNC = NodeConnectorCreator.createNodeConnector((short)10, NodeCreator.createOFNode((long)10));
NodeConnector outNC = NodeConnectorCreator.createNodeConnector((short)20, NodeCreator.createOFNode((long)20));
match.setField(MatchType.DL_TYPE, EtherTypes.IPv4.shortValue());
match.setField(MatchType.IN_PORT, inNC);
Output output = new Output(outNC);
ArrayList<Action> action = new ArrayList<Action>();
action.add(output);
Flow flow = new Flow (match, action);
FlowOnNode flowOnNode = new FlowOnNode (flow);
Assert.assertTrue(flowOnNode.getFlow().equals(flow));
flowOnNode.setPacketCount((long)100);
flowOnNode.setByteCount((long)800);
flowOnNode.setTableId((byte)0x55);
flowOnNode.setDurationNanoseconds(40);
flowOnNode.setDurationSeconds(45);
Assert.assertTrue(flowOnNode.getPacketCount() == 100);
Assert.assertTrue(flowOnNode.getByteCount() == 800);
Assert.assertTrue(flowOnNode.getDurationNanoseconds() == 40);
Assert.assertTrue(flowOnNode.getDurationSeconds() == 45);
Assert.assertTrue(flowOnNode.getTableId() == (byte)0x55);
}
示例14: getSampleFlowV6
import org.opendaylight.controller.sal.action.Action; //导入依赖的package包/类
private Flow getSampleFlowV6(Node node) throws UnknownHostException {
NodeConnector port = NodeConnectorCreator.createOFNodeConnector((short) 24, node);
NodeConnector oport = NodeConnectorCreator.createOFNodeConnector((short) 30, node);
byte srcMac[] = { (byte) 0x12, (byte) 0x34, (byte) 0x56, (byte) 0x78, (byte) 0x9a, (byte) 0xbc };
byte dstMac[] = { (byte) 0x1a, (byte) 0x2b, (byte) 0x3c, (byte) 0x4d, (byte) 0x5e, (byte) 0x6f };
byte newMac[] = { (byte) 0x11, (byte) 0xaa, (byte) 0xbb, (byte) 0x34, (byte) 0x9a, (byte) 0xee };
InetAddress srcIP = InetAddress.getByName("2001:420:281:1004:407a:57f4:4d15:c355");
InetAddress dstIP = InetAddress.getByName("2001:420:281:1004:e123:e688:d655:a1b0");
InetAddress ipMask = InetAddress.getByName("ffff:ffff:ffff:ffff:0:0:0:0");
InetAddress ipMask2 = InetAddress.getByName("ffff:ffff:ffff:ffff:ffff:ffff:ffff:0");
InetAddress newIP = InetAddress.getByName("2056:650::a1b0");
short ethertype = EtherTypes.IPv6.shortValue();
short vlan = (short) 27;
byte vlanPr = (byte) 3;
Byte tos = 4;
byte proto = IPProtocols.UDP.byteValue();
short src = (short) 5500;
short dst = 80;
/*
* Create a SAL Flow aFlow
*/
Match match = new Match();
match.setField(MatchType.IN_PORT, port);
match.setField(MatchType.DL_SRC, srcMac);
match.setField(MatchType.DL_DST, dstMac);
match.setField(MatchType.DL_TYPE, ethertype);
match.setField(MatchType.DL_VLAN, vlan);
match.setField(MatchType.DL_VLAN_PR, vlanPr);
match.setField(MatchType.NW_SRC, srcIP, ipMask);
match.setField(MatchType.NW_DST, dstIP, ipMask2);
match.setField(MatchType.NW_TOS, tos);
match.setField(MatchType.NW_PROTO, proto);
match.setField(MatchType.TP_SRC, src);
match.setField(MatchType.TP_DST, dst);
List<Action> actions = new ArrayList<Action>();
actions.add(new Controller());
actions.add(new SetVlanId(5));
actions.add(new SetDlDst(newMac));
actions.add(new SetNwDst(newIP));
actions.add(new Output(oport));
actions.add(new PopVlan());
actions.add(new Flood());
Flow flow = new Flow(match, actions);
flow.setPriority((short) 300);
flow.setHardTimeout((short) 240);
return flow;
}
示例15: replaceOutputPort
import org.opendaylight.controller.sal.action.Action; //导入依赖的package包/类
@Override
public void replaceOutputPort(Node node, String flowName, NodeConnector outPort) {
FlowEntry currentFlowEntry = null;
FlowEntry newFlowEntry = null;
// Find the flow
for (FlowEntryInstall index : this.nodeFlows.get(node)) {
FlowEntryInstall flow = this.installedSwView.get(index);
if (flow.getFlowName().equals(flowName)) {
currentFlowEntry = flow.getOriginal();
break;
}
}
if (currentFlowEntry == null) {
log.warn("Failed to replace output port for flow {} on node {}: Entry Not Found", flowName, node);
return;
}
// Create a flow copy with the new output port
newFlowEntry = currentFlowEntry.clone();
Action target = null;
for (Action action : newFlowEntry.getFlow().getActions()) {
if (action.getType() == ActionType.OUTPUT) {
target = action;
break;
}
}
newFlowEntry.getFlow().removeAction(target);
newFlowEntry.getFlow().addAction(new Output(outPort));
// Modify on network node
Status status = modifyEntry(currentFlowEntry, newFlowEntry, false);
if (status.isSuccess()) {
log.info("Output port replaced with {} for flow {} on node {}", outPort, flowName, node);
} else {
log.warn("Failed to replace output port for flow {} on node {}. The failure is: {}", flowName, node,
status.getDescription());
}
return;
}