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.mapper.egressnat;
11 import org.opendaylight.groupbasedpolicy.dto.EpKey;
12 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfContext;
13 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.OfWriter;
14 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.flow.FlowTable;
15 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTable;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.common.rev140421.L2BridgeDomainId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.NxmNxReg6;
24 import java.util.Collection;
27 * <h1>Manage the table that assigns source endpoint group, bridge domain, and
28 * router domain to registers to be used by other tables</h1>
33 * - ipv4/ipv6 inside address<br>
35 * - Reg6 {@link NxmNxReg6}<br>
37 * - set_src ip address<br>
38 * - {@link GoToTable} EXTERNAL MAPPER table<br>
40 public class EgressNatMapper extends FlowTable {
42 private static final Integer DROP = 1;
43 private static final Integer NAT = 100;
44 private final short tableId;
46 public EgressNatMapper(OfContext ctx, short tableId) {
48 this.tableId = tableId;
52 public short getTableId() {
57 public void sync(Endpoint endpoint, OfWriter ofWriter) throws Exception {
58 NodeId endpointNodeId = ctx.getEndpointManager().getEndpointNodeId(endpoint);
59 if (endpointNodeId == null) {
60 LOG.warn("Endpoint {} has no location specified, skipped", endpoint);
63 syncFlows(new EgressNatMapperFlows(endpointNodeId, tableId), endpoint, ofWriter);
66 void syncFlows(EgressNatMapperFlows flows, Endpoint endpoint, OfWriter ofWriter) {
69 flows.dropFlow(DROP, null, ofWriter);
72 short externalMapperId = ctx.getPolicyManager().getTABLEID_EXTERNAL_MAPPER();
73 Collection<EndpointL3> l3Endpoints = ctx.getEndpointManager().getL3EndpointsWithNat();
74 EndpointKey endpointKey = endpoint.getKey();
75 for (EndpointL3 l3Endpoint : l3Endpoints) {
76 L2BridgeDomainId l2Context = l3Endpoint.getL2Context();
77 MacAddress macAddress = l3Endpoint.getMacAddress();
78 if (l2Context != null && macAddress != null) {
79 Endpoint l2EpFromL3Ep = ctx.getEndpointManager().getEndpoint(new EpKey(l2Context, macAddress));
80 if(endpointKey.equals(l2EpFromL3Ep.getKey())) {
81 flows.natFlows(externalMapperId, l3Endpoint, NAT, ofWriter);
82 // L3 Endpoint found, end of loop