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.OfContext;
17 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.PolicyManager.Dirty;
18 import org.opendaylight.groupbasedpolicy.resolver.ConditionGroup;
19 import org.opendaylight.groupbasedpolicy.resolver.EgKey;
20 import org.opendaylight.groupbasedpolicy.resolver.IndexedTenant;
21 import org.opendaylight.groupbasedpolicy.resolver.PolicyInfo;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.ConditionName;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.EndpointLocation.LocationType;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayContext;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.EndpointGroup;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.L2BridgeDomain;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.L2FloodDomain;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.L3Context;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg0;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg1;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg4;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg5;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
46 import static org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowUtils.*;
49 * Manage the table that assigns source endpoint group, bridge domain, and
50 * router domain to registers to be used by other tables.
53 public class SourceMapper extends FlowTable {
54 protected static final Logger LOG =
55 LoggerFactory.getLogger(SourceMapper.class);
57 public static final short TABLE_ID = 1;
59 public SourceMapper(OfContext ctx) {
64 public short getTableId() {
69 public void sync(ReadWriteTransaction t,
70 InstanceIdentifier<Table> tiid,
71 Map<String, FlowCtx> flowMap,
72 NodeId nodeId, PolicyInfo policyInfo,
73 Dirty dirty) throws Exception {
74 dropFlow(t, tiid, flowMap, Integer.valueOf(1), null);
76 for (EgKey sepg : ctx.getEndpointManager().getGroupsForNode(nodeId)) {
77 IndexedTenant tenant =
78 ctx.getPolicyResolver().getTenant(sepg.getTenantId());
79 if (tenant == null) continue;
81 EndpointGroup eg = tenant.getEndpointGroup(sepg.getEgId());
82 L3Context l3c = tenant.resolveL3Context(eg.getNetworkDomain());
83 L2BridgeDomain bd = tenant.resolveL2BridgeDomain(eg.getNetworkDomain());
84 L2FloodDomain fd = tenant.resolveL2FloodDomain(eg.getNetworkDomain());
85 int egId = 0, bdId = 0, fdId = 0, l3Id = 0;
87 egId = ctx.getPolicyManager().getContextOrdinal(sepg.getTenantId(),
90 bdId = ctx.getPolicyManager().getContextOrdinal(sepg.getTenantId(),
93 fdId = ctx.getPolicyManager().getContextOrdinal(sepg.getTenantId(),
96 l3Id = ctx.getPolicyManager().getContextOrdinal(sepg.getTenantId(),
99 NodeConnectorId tunPort =
100 ctx.getSwitchManager().getTunnelPort(nodeId);
101 if (tunPort != null) {
102 FlowId flowid = new FlowId(new StringBuilder()
103 .append(tunPort.getValue())
113 if (visit(flowMap, flowid.getValue())) {
114 MatchBuilder mb = new MatchBuilder()
116 addNxTunIdMatch(mb, egId);
117 Action segReg = nxLoadRegAction(NxmNxReg0.class,
118 BigInteger.valueOf(egId));
119 // set condition group register to all ones to bypass
120 // policy enforcement
121 Action scgReg = nxLoadRegAction(NxmNxReg1.class,
122 BigInteger.valueOf(0xffffff));
123 Action bdReg = nxLoadRegAction(NxmNxReg4.class,
124 BigInteger.valueOf(bdId));
125 Action fdReg = nxLoadRegAction(NxmNxReg5.class,
126 BigInteger.valueOf(fdId));
127 Action vrfReg = nxLoadRegAction(NxmNxReg6.class,
128 BigInteger.valueOf(l3Id));
129 FlowBuilder flowb = base()
131 .setPriority(Integer.valueOf(150))
132 .setMatch(mb.build())
133 .setInstructions(instructions(applyActionIns(segReg,
138 gotoTableIns((short)(TABLE_ID + 1))));
139 writeFlow(t, tiid, flowb.build());
143 for (Endpoint e : ctx.getEndpointManager().getEPsForNode(nodeId, sepg)) {
144 OfOverlayContext ofc = e.getAugmentation(OfOverlayContext.class);
145 if (ofc != null && ofc.getNodeConnectorId() != null &&
146 (ofc.getLocationType() == null ||
147 LocationType.Internal.equals(ofc.getLocationType())) &&
148 e.getTenant() != null && e.getEndpointGroup() != null) {
149 syncEP(t, tiid, flowMap, policyInfo, nodeId, e, ofc,
150 egId, bdId, fdId, l3Id);
156 private void syncEP(ReadWriteTransaction t,
157 InstanceIdentifier<Table> tiid,
158 Map<String, FlowCtx> flowMap,
159 PolicyInfo policyInfo,
160 NodeId nodeId, Endpoint e, OfOverlayContext ofc,
161 int egId, int bdId, int fdId, int l3Id)
163 // Set sEPG, flood domain, bridge domain, and layer 3 context
164 // for internal endpoints by directly matching each endpoint
166 List<ConditionName> conds = ctx.getEndpointManager().getCondsForEndpoint(e);
168 policyInfo.getEgCondGroup(new EgKey(e.getTenant(),
169 e.getEndpointGroup()),
171 int cgId = ctx.getPolicyManager().getCondGroupOrdinal(cg);
173 FlowId flowid = new FlowId(new StringBuilder()
174 .append(ofc.getNodeConnectorId().getValue())
176 .append(e.getMacAddress().getValue())
188 if (visit(flowMap, flowid.getValue())) {
189 Action segReg = nxLoadRegAction(NxmNxReg0.class,
190 BigInteger.valueOf(egId));
191 Action scgReg = nxLoadRegAction(NxmNxReg1.class,
192 BigInteger.valueOf(cgId));
193 Action bdReg = nxLoadRegAction(NxmNxReg4.class,
194 BigInteger.valueOf(bdId));
195 Action fdReg = nxLoadRegAction(NxmNxReg5.class,
196 BigInteger.valueOf(fdId));
197 Action vrfReg = nxLoadRegAction(NxmNxReg6.class,
198 BigInteger.valueOf(l3Id));
199 FlowBuilder flowb = base()
200 .setPriority(Integer.valueOf(100))
202 .setMatch(new MatchBuilder()
203 .setEthernetMatch(ethernetMatch(e.getMacAddress(),
205 .setInPort(ofc.getNodeConnectorId())
207 .setInstructions(instructions(applyActionIns(segReg,
212 gotoTableIns((short)(TABLE_ID + 1))));
213 writeFlow(t, tiid, flowb.build());