2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
9 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow;
\r
11 import java.math.BigInteger;
\r
12 import java.util.HashMap;
\r
13 import java.util.List;
\r
14 import java.util.Objects;
\r
16 import org.junit.Before;
\r
17 import org.junit.Test;
\r
18 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager.FlowMap;
\r
19 import org.opendaylight.groupbasedpolicy.resolver.ConditionGroup;
\r
20 import org.opendaylight.groupbasedpolicy.resolver.EgKey;
\r
21 import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
\r
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
\r
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
\r
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
\r
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
\r
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ConditionName;
\r
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.NetworkDomainId;
\r
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
\r
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;
\r
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg1;
\r
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
\r
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;
\r
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
\r
34 import org.slf4j.Logger;
\r
35 import org.slf4j.LoggerFactory;
\r
37 import com.google.common.collect.ImmutableList;
\r
39 import static org.junit.Assert.*;
\r
41 public class SourceMapperTest extends FlowTableTest {
\r
43 protected static final Logger LOG = LoggerFactory.getLogger(SourceMapperTest.class);
\r
46 public void setup() throws Exception {
\r
48 table = new SourceMapper(ctx);
\r
53 public void testNoPolicy() throws Exception {
\r
54 endpointManager.addEndpoint(localEP().build());
\r
55 FlowMap fm = dosync(null);
\r
56 assertEquals(1, fm.getTableForNode(nodeId, (short) 1).getFlow().size());
\r
60 public void testMap() throws Exception {
\r
61 Endpoint ep = localEP().build();
\r
62 endpointManager.addEndpoint(ep);
\r
63 policyResolver.addTenant(baseTenant().build());
\r
65 FlowMap fm = dosync(null);
\r
66 assertEquals(2, fm.getTableForNode(nodeId, (short) 1).getFlow().size());
\r
69 HashMap<String, Flow> flowMap = new HashMap<>();
\r
70 for (Flow f : fm.getTableForNode(nodeId, (short) 1).getFlow()) {
\r
71 flowMap.put(f.getId().getValue(), f);
\r
72 if (f.getMatch() == null) {
\r
73 assertEquals(FlowUtils.dropInstructions(), f.getInstructions());
\r
75 } else if (Objects.equals(ep.getMacAddress(), f.getMatch()
\r
77 .getEthernetSource()
\r
79 PolicyInfo pi = policyResolver.getCurrentPolicy();
\r
80 List<ConditionName> cset = endpointManager.getCondsForEndpoint(ep);
\r
81 ConditionGroup cg = pi.getEgCondGroup(new EgKey(tid, eg), cset);
\r
83 Instruction ins = f.getInstructions().getInstruction().get(0);
\r
84 assertTrue(ins.getInstruction() instanceof ApplyActionsCase);
\r
85 List<Action> actions = ((ApplyActionsCase) ins.getInstruction()).getApplyActions().getAction();
\r
86 NetworkDomainId networkContainement = policyResolver.getTenant(tid)
\r
87 .getEndpointGroup(eg)
\r
88 .getNetworkDomain();
\r
89 int v = OrdinalFactory.getContextOrdinal(ep, networkContainement);
\r
90 assertEquals(FlowUtils.nxLoadRegAction(NxmNxReg0.class, BigInteger.valueOf(v)), actions.get(0)
\r
92 v = OrdinalFactory.getCondGroupOrdinal(cg);
\r
93 assertEquals(FlowUtils.nxLoadRegAction(NxmNxReg1.class, BigInteger.valueOf(v)), actions.get(1)
\r
95 v = OrdinalFactory.getContextOrdinal(tid, bd);
\r
96 assertEquals(FlowUtils.nxLoadRegAction(NxmNxReg4.class, BigInteger.valueOf(v)), actions.get(2)
\r
98 v = OrdinalFactory.getContextOrdinal(tid, fd);
\r
99 assertEquals(FlowUtils.nxLoadRegAction(NxmNxReg5.class, BigInteger.valueOf(v)), actions.get(3)
\r
101 v = OrdinalFactory.getContextOrdinal(tid, l3c);
\r
102 assertEquals(FlowUtils.nxLoadRegAction(NxmNxReg6.class, BigInteger.valueOf(v)), actions.get(4)
\r
107 assertEquals(2, count);
\r
108 int numberOfFlows = fm.getTableForNode(nodeId, (short) 1).getFlow().size();
\r
109 fm = dosync(flowMap);
\r
110 assertEquals(numberOfFlows, fm.getTableForNode(nodeId, (short) 1).getFlow().size());
\r