2 * Copyright (c) 2014, 2015 Red Hat, 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.ovsdb.openstack.netvirt.providers.openflow13.services;
11 import java.math.BigInteger;
12 import java.net.Inet6Address;
13 import java.net.InetAddress;
14 import java.util.List;
16 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
17 import org.opendaylight.ovsdb.openstack.netvirt.api.L3ForwardingProvider;
18 import org.opendaylight.ovsdb.openstack.netvirt.api.Status;
19 import org.opendaylight.ovsdb.openstack.netvirt.api.StatusCode;
20 import org.opendaylight.ovsdb.openstack.netvirt.providers.ConfigInterface;
21 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.AbstractServiceInstance;
22 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
23 import org.opendaylight.ovsdb.utils.mdsal.openflow.FlowUtils;
24 import org.opendaylight.ovsdb.utils.mdsal.openflow.InstructionUtils;
25 import org.opendaylight.ovsdb.utils.mdsal.openflow.MatchUtils;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 import com.google.common.collect.Lists;
38 import org.osgi.framework.BundleContext;
39 import org.osgi.framework.ServiceReference;
41 public class L3ForwardingService extends AbstractServiceInstance implements L3ForwardingProvider, ConfigInterface {
42 private static final Logger LOG = LoggerFactory.getLogger(L3ForwardingService.class);
44 public L3ForwardingService() {
45 super(Service.L3_FORWARDING);
48 public L3ForwardingService(Service service) {
53 public Status programForwardingTableEntry(Long dpid, String segmentationId, InetAddress ipAddress,
54 String macAddress, Action action) {
55 if (ipAddress instanceof Inet6Address) {
56 // WORKAROUND: For now ipv6 is not supported
57 // TODO: implement ipv6 case
58 LOG.debug("ipv6 address is not implemented yet. dpid {} segmentationId {} ipAddress {} macAddress {} Action {}",
59 dpid, segmentationId, ipAddress, macAddress, action);
60 return new Status(StatusCode.NOTIMPLEMENTED);
63 NodeBuilder nodeBuilder = FlowUtils.createNodeBuilder(dpid);
64 FlowBuilder flowBuilder = new FlowBuilder();
65 String flowName = "L3Forwarding_" + segmentationId + "_" + ipAddress.getHostAddress();
66 FlowUtils.initFlowBuilder(flowBuilder, flowName, getTable()).setPriority(1024);
68 MatchBuilder matchBuilder = new MatchBuilder();
69 MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId));
70 MatchUtils.createDstL3IPv4Match(matchBuilder, MatchUtils.iPv4PrefixFromIPv4Address(ipAddress.getHostAddress()));
72 flowBuilder.setMatch(matchBuilder.build());
74 if (action.equals(Action.ADD)) {
75 // Instructions List Stores Individual Instructions
76 InstructionsBuilder isb = new InstructionsBuilder();
77 List<Instruction> instructions = Lists.newArrayList();
78 InstructionBuilder ib = new InstructionBuilder();
80 // Set Dest Mac address
81 InstructionUtils.createDlDstInstructions(ib, new MacAddress(macAddress));
83 ib.setKey(new InstructionKey(0));
84 instructions.add(ib.build());
87 ib = getMutablePipelineInstructionBuilder();
89 ib.setKey(new InstructionKey(1));
90 instructions.add(ib.build());
92 flowBuilder.setInstructions(isb.setInstruction(instructions).build());
94 writeFlow(flowBuilder, nodeBuilder);
96 removeFlow(flowBuilder, nodeBuilder);
99 // ToDo: WriteFlow/RemoveFlow should return something we can use to check success
100 return new Status(StatusCode.SUCCESS);
104 public void setDependencies(BundleContext bundleContext, ServiceReference serviceReference) {
105 super.setDependencies(bundleContext.getServiceReference(L3ForwardingProvider.class.getName()), this);
109 public void setDependencies(Object impl) {