2 * Copyright © 2017 Ericsson India Global Services Pvt Ltd. 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
8 package org.opendaylight.netvirt.fibmanager;
10 import java.util.ArrayList;
11 import java.util.List;
12 import javax.inject.Inject;
13 import javax.inject.Singleton;
14 import org.opendaylight.genius.mdsalutil.ActionInfo;
15 import org.opendaylight.genius.mdsalutil.FlowEntity;
16 import org.opendaylight.genius.mdsalutil.InstructionInfo;
17 import org.opendaylight.genius.mdsalutil.MDSALUtil;
18 import org.opendaylight.genius.mdsalutil.MatchInfo;
19 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
20 import org.opendaylight.genius.mdsalutil.NwConstants;
21 import org.opendaylight.genius.mdsalutil.actions.ActionMoveSourceDestinationEth;
22 import org.opendaylight.genius.mdsalutil.actions.ActionMoveSourceDestinationIpv6;
23 import org.opendaylight.genius.mdsalutil.actions.ActionNxLoadInPort;
24 import org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit;
25 import org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource;
26 import org.opendaylight.genius.mdsalutil.actions.ActionSetIcmpv6Type;
27 import org.opendaylight.genius.mdsalutil.actions.ActionSetSourceIpv6;
28 import org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions;
29 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
30 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetType;
31 import org.opendaylight.genius.mdsalutil.matches.MatchIcmpv6;
32 import org.opendaylight.genius.mdsalutil.matches.MatchIpProtocol;
33 import org.opendaylight.genius.mdsalutil.matches.MatchIpv6Destination;
34 import org.opendaylight.genius.mdsalutil.matches.MatchMetadata;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
37 import org.opendaylight.yangtools.yang.common.Uint32;
38 import org.opendaylight.yangtools.yang.common.Uint64;
41 public class IPv6Handler {
42 private final IMdsalApiManager mdsalManager;
45 public IPv6Handler(final IMdsalApiManager mdsalManager) {
46 this.mdsalManager = mdsalManager;
49 public void installPing6ResponderFlowEntry(Uint64 dpnId, Uint32 vpnId, String routerInternalIp,
50 MacAddress routerMac, Uint32 label, int addOrRemove) {
52 List<MatchInfo> matches = new ArrayList<>();
53 matches.add(MatchIpProtocol.ICMPV6);
54 matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId.longValue()),
55 MetaDataUtil.METADATA_MASK_VRFID));
56 matches.add(new MatchIcmpv6((short) 128, (short) 0));
57 matches.add(MatchEthernetType.IPV6);
58 matches.add(new MatchIpv6Destination(routerInternalIp));
60 List<ActionInfo> actionsInfos = new ArrayList<>();
61 // Set Eth Src and Eth Dst
62 actionsInfos.add(new ActionMoveSourceDestinationEth());
63 actionsInfos.add(new ActionSetFieldEthernetSource(routerMac));
65 // Move Ipv6 Src to Ipv6 Dst
66 actionsInfos.add(new ActionMoveSourceDestinationIpv6());
67 actionsInfos.add(new ActionSetSourceIpv6(new Ipv6Prefix(routerInternalIp)));
69 // Set the ICMPv6 type to 129 (echo reply)
70 actionsInfos.add(new ActionSetIcmpv6Type((short) 129));
71 actionsInfos.add(new ActionNxLoadInPort(Uint64.ZERO));
72 actionsInfos.add(new ActionNxResubmit(NwConstants.L3_FIB_TABLE));
73 List<InstructionInfo> instructions = new ArrayList<>();
74 instructions.add(new InstructionApplyActions(actionsInfos));
76 int priority = FibConstants.DEFAULT_FIB_FLOW_PRIORITY + FibConstants.DEFAULT_IPV6_PREFIX_LENGTH;
77 String flowRef = FibUtil.getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, label, priority);
79 FlowEntity flowEntity = MDSALUtil.buildFlowEntity(dpnId, NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef,
80 0, 0, NwConstants.COOKIE_VM_FIB_TABLE, matches, instructions);
82 if (addOrRemove == NwConstants.ADD_FLOW) {
83 mdsalManager.syncInstallFlow(flowEntity);
85 mdsalManager.syncRemoveFlow(flowEntity);