2 * Copyright (C) 2014 Red Hat, Inc.
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 * Authors : Dave Tucker
11 package org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.services;
13 import java.math.BigInteger;
14 import java.net.InetAddress;
15 import java.util.List;
17 import org.opendaylight.controller.sal.core.Node;
18 import org.opendaylight.controller.sal.utils.Status;
19 import org.opendaylight.controller.sal.utils.StatusCode;
20 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
21 import org.opendaylight.ovsdb.openstack.netvirt.api.Constants;
22 import org.opendaylight.ovsdb.openstack.netvirt.api.L3ForwardingProvider;
23 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.AbstractServiceInstance;
24 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.OF13Provider;
25 import org.opendaylight.ovsdb.openstack.netvirt.providers.openflow13.Service;
26 import org.opendaylight.ovsdb.utils.mdsal.openflow.InstructionUtils;
27 import org.opendaylight.ovsdb.utils.mdsal.openflow.MatchUtils;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
29 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeBuilder;
40 import com.google.common.collect.Lists;
42 public class L3ForwardingService extends AbstractServiceInstance implements L3ForwardingProvider {
43 public L3ForwardingService() {
44 super(Service.L3_FORWARDING);
47 public L3ForwardingService(Service service) {
52 public boolean isBridgeInPipeline (String nodeId) {
57 public Status programForwardingTableEntry(Node node, Long dpid, String segmentationId, InetAddress ipAddress,
58 String macAddress, Action action) {
59 String nodeName = Constants.OPENFLOW_NODE_PREFIX + dpid;
61 MatchBuilder matchBuilder = new MatchBuilder();
62 NodeBuilder nodeBuilder = OF13Provider.createNodeBuilder(nodeName);
64 // Instructions List Stores Individual Instructions
65 InstructionsBuilder isb = new InstructionsBuilder();
66 List<Instruction> instructions = Lists.newArrayList();
67 InstructionBuilder ib = new InstructionBuilder();
69 MatchUtils.createTunnelIDMatch(matchBuilder, new BigInteger(segmentationId));
70 MatchUtils.createDstL3IPv4Match(matchBuilder, new Ipv4Prefix(ipAddress.getHostAddress()));
72 // Set Dest Mac address
73 InstructionUtils.createDlDstInstructions(ib, new MacAddress(macAddress));
75 ib.setKey(new InstructionKey(0));
76 instructions.add(ib.build());
79 ib = getMutablePipelineInstructionBuilder();
81 ib.setKey(new InstructionKey(1));
82 instructions.add(ib.build());
84 FlowBuilder flowBuilder = new FlowBuilder();
85 flowBuilder.setMatch(matchBuilder.build());
86 flowBuilder.setInstructions(isb.setInstruction(instructions).build());
88 String flowId = "L3Forwarding_" + ipAddress.getHostAddress();
89 flowBuilder.setId(new FlowId(flowId));
90 FlowKey key = new FlowKey(new FlowId(flowId));
91 flowBuilder.setBarrier(true);
92 flowBuilder.setTableId(this.getTable());
93 flowBuilder.setKey(key);
94 flowBuilder.setPriority(1024);
95 flowBuilder.setFlowName(flowId);
96 flowBuilder.setHardTimeout(0);
97 flowBuilder.setIdleTimeout(0);
99 if (action.equals(Action.ADD)) {
100 writeFlow(flowBuilder, nodeBuilder);
102 removeFlow(flowBuilder, nodeBuilder);
105 // ToDo: WriteFlow/RemoveFlow should return something we can use to check success
106 return new Status(StatusCode.SUCCESS);