2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow;
11 import java.math.BigInteger;
12 import java.util.List;
15 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
16 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager.Dirty;
17 import org.opendaylight.groupbasedpolicy.resolver.ConditionGroup;
18 import org.opendaylight.groupbasedpolicy.resolver.EgKey;
19 import org.opendaylight.groupbasedpolicy.resolver.IndexedTenant;
20 import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ConditionName;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.EndpointLocation.LocationType;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContext;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.EndpointGroup;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.L2BridgeDomain;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.L2FloodDomain;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.L3Context;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg1;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
41 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
45 import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.*;
48 * Manage the table that assigns source endpoint group, bridge domain, and
49 * router domain to registers to be used by other tables.
52 public class SourceMapper extends FlowTable {
53 protected static final Logger LOG =
54 LoggerFactory.getLogger(SourceMapper.class);
56 public static final short TABLE_ID = 1;
58 public SourceMapper(OfTable.OfTableCtx ctx) {
63 public short getTableId() {
68 public void sync(ReadWriteTransaction t,
69 InstanceIdentifier<Table> tiid,
70 Map<String, FlowCtx> flowMap,
71 NodeId nodeId, PolicyInfo policyInfo,
72 Dirty dirty) throws Exception {
73 dropFlow(t, tiid, flowMap, Integer.valueOf(1), null);
75 for (EgKey sepg : ctx.epManager.getGroupsForNode(nodeId)) {
76 IndexedTenant tenant =
77 ctx.policyResolver.getTenant(sepg.getTenantId());
78 if (tenant == null) continue;
80 EndpointGroup eg = tenant.getEndpointGroup(sepg.getEgId());
81 L3Context l3c = tenant.resolveL3Context(eg.getNetworkDomain());
82 L2BridgeDomain bd = tenant.resolveL2BridgeDomain(eg.getNetworkDomain());
83 L2FloodDomain fd = tenant.resolveL2FloodDomain(eg.getNetworkDomain());
84 int egId = 0, bdId = 0, fdId = 0, l3Id = 0;
86 egId = ctx.policyManager.getContextOrdinal(sepg.getTenantId(),
89 bdId = ctx.policyManager.getContextOrdinal(sepg.getTenantId(),
92 fdId = ctx.policyManager.getContextOrdinal(sepg.getTenantId(),
95 l3Id = ctx.policyManager.getContextOrdinal(sepg.getTenantId(),
98 NodeConnectorId tunPort =
99 ctx.switchManager.getTunnelPort(nodeId);
100 if (tunPort != null) {
101 FlowId flowid = new FlowId(new StringBuilder()
102 .append(tunPort.getValue())
112 if (visit(flowMap, flowid.getValue())) {
113 MatchBuilder mb = new MatchBuilder()
115 addNxTunIdMatch(mb, egId);
116 Action segReg = nxLoadRegAction(NxmNxReg0.class,
117 BigInteger.valueOf(egId));
118 // set condition group register to all ones to bypass
119 // policy enforcement
120 Action scgReg = nxLoadRegAction(NxmNxReg1.class,
121 BigInteger.valueOf(0xffffff));
122 Action bdReg = nxLoadRegAction(NxmNxReg4.class,
123 BigInteger.valueOf(bdId));
124 Action fdReg = nxLoadRegAction(NxmNxReg5.class,
125 BigInteger.valueOf(fdId));
126 Action vrfReg = nxLoadRegAction(NxmNxReg6.class,
127 BigInteger.valueOf(l3Id));
128 FlowBuilder flowb = base()
130 .setPriority(Integer.valueOf(150))
131 .setMatch(mb.build())
132 .setInstructions(instructions(applyActionIns(segReg,
137 gotoTableIns((short)(TABLE_ID + 1))));
138 writeFlow(t, tiid, flowb.build());
142 for (Endpoint e : ctx.epManager.getEPsForNode(nodeId, sepg)) {
143 OfOverlayContext ofc = e.getAugmentation(OfOverlayContext.class);
144 if (ofc != null && ofc.getNodeConnectorId() != null &&
145 (ofc.getLocationType() == null ||
146 LocationType.Internal.equals(ofc.getLocationType())) &&
147 e.getTenant() != null && e.getEndpointGroup() != null) {
148 syncEP(t, tiid, flowMap, policyInfo, nodeId, e, ofc,
149 egId, bdId, fdId, l3Id);
155 private void syncEP(ReadWriteTransaction t,
156 InstanceIdentifier<Table> tiid,
157 Map<String, FlowCtx> flowMap,
158 PolicyInfo policyInfo,
159 NodeId nodeId, Endpoint e, OfOverlayContext ofc,
160 int egId, int bdId, int fdId, int l3Id)
162 // Set sEPG, flood domain, bridge domain, and layer 3 context
163 // for internal endpoints by directly matching each endpoint
165 List<ConditionName> conds = ctx.epManager.getCondsForEndpoint(e);
167 policyInfo.getEgCondGroup(new EgKey(e.getTenant(),
168 e.getEndpointGroup()),
170 int cgId = ctx.policyManager.getCondGroupOrdinal(cg);
172 FlowId flowid = new FlowId(new StringBuilder()
173 .append(ofc.getNodeConnectorId().getValue())
175 .append(e.getMacAddress().getValue())
187 if (visit(flowMap, flowid.getValue())) {
188 Action segReg = nxLoadRegAction(NxmNxReg0.class,
189 BigInteger.valueOf(egId));
190 Action scgReg = nxLoadRegAction(NxmNxReg1.class,
191 BigInteger.valueOf(cgId));
192 Action bdReg = nxLoadRegAction(NxmNxReg4.class,
193 BigInteger.valueOf(bdId));
194 Action fdReg = nxLoadRegAction(NxmNxReg5.class,
195 BigInteger.valueOf(fdId));
196 Action vrfReg = nxLoadRegAction(NxmNxReg6.class,
197 BigInteger.valueOf(l3Id));
198 FlowBuilder flowb = base()
199 .setPriority(Integer.valueOf(100))
201 .setMatch(new MatchBuilder()
202 .setEthernetMatch(ethernetMatch(e.getMacAddress(),
204 .setInPort(ofc.getNodeConnectorId())
206 .setInstructions(instructions(applyActionIns(segReg,
211 gotoTableIns((short)(TABLE_ID + 1))));
212 writeFlow(t, tiid, flowb.build());