2 * Copyright (c) 2013 Cisco Systems, 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
8 package org.opendaylight.openflowplugin.droptest;
10 import java.math.BigInteger;
12 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
31 import com.google.common.base.Preconditions;
33 public class DropTestCommiter extends AbstractDropTest {
34 private final static Logger LOG = LoggerFactory.getLogger(DropTestProvider.class);
36 private static final ThreadLocal<FlowBuilder> BUILDER = new ThreadLocal<FlowBuilder>() {
38 protected FlowBuilder initialValue() {
39 final FlowBuilder fb = new FlowBuilder();
43 final FlowCookie cookie = new FlowCookie(BigInteger.valueOf(10));
45 fb.setCookieMask(cookie);
47 fb.setTableId((short) 0);
48 fb.setHardTimeout(300);
49 fb.setIdleTimeout(240);
50 fb.setFlags(new FlowModFlags(false, false, false, false, false));
55 private final DropTestProvider manager;
57 public DropTestCommiter(final DropTestProvider manager) {
58 this.manager = Preconditions.checkNotNull(manager);
62 protected void processPacket(final NodeKey node, final Match match, final Instructions instructions) {
64 // Finally build our flow
65 final FlowBuilder fb = BUILDER.get();
67 fb.setInstructions(instructions);
68 fb.setId(new FlowId(String.valueOf(fb.hashCode())));
70 // Construct the flow instance id
71 final InstanceIdentifier<Flow> flowInstanceId =
72 InstanceIdentifier.builder(Nodes.class) // File under nodes
73 .child(Node.class, node) // A particular node identified by nodeKey
74 .augmentation(FlowCapableNode.class) // That is flow capable, only FlowCapableNodes have tables
75 .child(Table.class, new TableKey((short) 0)) // In the table identified by TableKey
76 .child(Flow.class, new FlowKey(fb.getId())) // A flow identified by flowKey
79 final Flow flow = fb.build();
80 final DataModificationTransaction transaction = manager.getDataService().beginTransaction();
82 LOG.debug("onPacketReceived - About to write flow {}", flow);
83 transaction.putConfigurationData(flowInstanceId, flow);
85 LOG.debug("onPacketReceived - About to write flow commited");