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