2 * Copyright (c) 2017 6WIND, Inc. 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
8 package org.opendaylight.netvirt.neutronvpn;
10 import java.math.BigInteger;
11 import java.util.ArrayList;
12 import java.util.List;
14 import javax.inject.Inject;
15 import javax.inject.Singleton;
17 import org.opendaylight.genius.mdsalutil.FlowEntity;
18 import org.opendaylight.genius.mdsalutil.InstructionInfo;
19 import org.opendaylight.genius.mdsalutil.MDSALUtil;
20 import org.opendaylight.genius.mdsalutil.MatchInfo;
21 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
22 import org.opendaylight.genius.mdsalutil.NwConstants;
23 import org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable;
24 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
25 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetType;
26 import org.opendaylight.genius.mdsalutil.matches.MatchMetadata;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
31 public class IPV6InternetDefaultRouteProgrammer {
33 private static final Logger LOG = LoggerFactory.getLogger(IPV6InternetDefaultRouteProgrammer.class);
34 private final IMdsalApiManager mdsalManager;
37 public IPV6InternetDefaultRouteProgrammer(final IMdsalApiManager mdsalManager) {
38 this.mdsalManager = mdsalManager;
41 private FlowEntity buildIPv6FallbacktoExternalVpn(BigInteger dpId, long bgpVpnId, long routerId) {
42 List<MatchInfo> matches = new ArrayList<>();
43 matches.add(MatchEthernetType.IPV6);
46 matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(bgpVpnId), MetaDataUtil.METADATA_MASK_VRFID));
48 List<InstructionInfo> instructions = new ArrayList<>();
50 instructions.add(new InstructionGotoTable(NwConstants.EXTERNAL_TUNNEL_TABLE));
52 String defaultIPv6 = "0:0:0:0:0:0:0:0";
53 String flowRef = getIPv6FlowRefL3(dpId, NwConstants.L3_FIB_TABLE, defaultIPv6, routerId);
55 FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_FIB_TABLE, flowRef,
56 NwConstants.TABLE_MISS_PRIORITY, flowRef/* "L3 ipv6 internet default route",*/, 0, 0,
57 NwConstants.COOKIE_VM_FIB_TABLE, matches, instructions);
63 * This method installs in the FIB table the default route for IPv6.
65 * @param dpnId of the compute node
66 * @param bgpVpnId internetVpn id as long
67 * @param routerId id of router associated to internet bgpvpn as long
69 public void installDefaultRoute(BigInteger dpnId, long bgpVpnId, long routerId) {
70 FlowEntity flowEntity = buildIPv6FallbacktoExternalVpn(dpnId, bgpVpnId, routerId);
71 LOG.trace("installDefaultRoute: flowEntity: {} ", flowEntity);
72 mdsalManager.installFlow(flowEntity);
75 public void removeDefaultRoute(BigInteger dpnId, long bgpVpnId, long routerId) {
76 FlowEntity flowEntity = buildIPv6FallbacktoExternalVpn(dpnId, bgpVpnId, routerId);
77 LOG.trace("removeDefaultRoute: flowEntity: {} ", flowEntity);
78 mdsalManager.removeFlow(flowEntity);
81 public String getIPv6FlowRefL3(BigInteger dpnId, short tableId, String destPrefix, long vpnId) {
82 return "L3." + dpnId.toString() + NwConstants.FLOWID_SEPARATOR + tableId
83 + NwConstants.FLOWID_SEPARATOR + destPrefix + NwConstants.FLOWID_SEPARATOR + vpnId;