Adjust to RPC method signature update
[netvirt.git] / neutronvpn / impl / src / main / java / org / opendaylight / netvirt / neutronvpn / IPV6InternetDefaultRouteProgrammer.java
1 /*
2  * Copyright (c) 2017 6WIND, Inc. All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netvirt.neutronvpn;
9
10 import java.math.BigInteger;
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import javax.inject.Inject;
15 import javax.inject.Singleton;
16
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;
29
30 @Singleton
31 public class IPV6InternetDefaultRouteProgrammer {
32
33     private static final Logger LOG = LoggerFactory.getLogger(IPV6InternetDefaultRouteProgrammer.class);
34     private final IMdsalApiManager mdsalManager;
35
36     @Inject
37     public IPV6InternetDefaultRouteProgrammer(final IMdsalApiManager mdsalManager) {
38         this.mdsalManager = mdsalManager;
39     }
40
41     private FlowEntity buildIPv6FallbacktoExternalVpn(BigInteger dpId, long bgpVpnId, long routerId) {
42         List<MatchInfo> matches = new ArrayList<>();
43         matches.add(MatchEthernetType.IPV6);
44
45         //add match for vrfid
46         matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(bgpVpnId), MetaDataUtil.METADATA_MASK_VRFID));
47
48         List<InstructionInfo> instructions = new ArrayList<>();
49
50         instructions.add(new InstructionGotoTable(NwConstants.EXTERNAL_TUNNEL_TABLE));
51
52         String defaultIPv6 = "0:0:0:0:0:0:0:0";
53         String flowRef = getIPv6FlowRefL3(dpId, NwConstants.L3_FIB_TABLE, defaultIPv6, routerId);
54
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);
58
59         return flowEntity;
60     }
61
62     /**
63      * This method installs in the FIB table the default route for IPv6.
64      *
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
68      */
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);
73     }
74
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);
79     }
80
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;
84     }
85 }