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 com.google.common.base.Preconditions;
11 import java.math.BigInteger;
12 import org.opendaylight.controller.md.sal.binding.api.ReadWriteTransaction;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class DropTestCommiter extends AbstractDropTest {
33 private final static Logger LOG = LoggerFactory.getLogger(DropTestProvider.class);
35 private static final ThreadLocal<FlowBuilder> BUILDER = new ThreadLocal<FlowBuilder>() {
37 protected FlowBuilder initialValue() {
38 final FlowBuilder fb = new FlowBuilder();
42 final FlowCookie cookie = new FlowCookie(BigInteger.valueOf(10));
44 fb.setCookieMask(cookie);
46 fb.setTableId((short) 0);
47 fb.setHardTimeout(300);
48 fb.setIdleTimeout(240);
49 fb.setFlags(new FlowModFlags(false, false, false, false, false));
54 private final DropTestProvider manager;
56 public DropTestCommiter(final DropTestProvider manager) {
57 this.manager = Preconditions.checkNotNull(manager);
61 protected void processPacket(final NodeKey node, final Match match, final Instructions instructions) {
63 // Finally build our flow
64 final FlowBuilder fb = BUILDER.get();
66 fb.setInstructions(instructions);
67 fb.setId(new FlowId(String.valueOf(fb.hashCode())));
69 // Construct the flow instance id
70 final InstanceIdentifier<Flow> flowInstanceId =
71 InstanceIdentifier.builder(Nodes.class) // File under nodes
72 .child(Node.class, node) // A particular node identified by nodeKey
73 .augmentation(FlowCapableNode.class) // That is flow capable, only FlowCapableNodes have tables
74 .child(Table.class, new TableKey((short) 0)) // In the table identified by TableKey
75 .child(Flow.class, new FlowKey(fb.getId())) // A flow identified by flowKey
78 final Flow flow = fb.build();
79 final ReadWriteTransaction transaction = manager.getDataService().newReadWriteTransaction();
81 LOG.debug("onPacketReceived - About to write flow {}", flow);
82 transaction.put(LogicalDatastoreType.CONFIGURATION, flowInstanceId, flow, true);
84 LOG.debug("onPacketReceived - About to write flow commited");