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.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Match;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
26 public class DropTestRpcSender extends AbstractDropTest {
27 private final static Logger LOG = LoggerFactory.getLogger(DropTestProvider.class);
29 private final SalFlowService flowService;
31 public DropTestRpcSender(final SalFlowService flowService) {
32 this.flowService = flowService;
35 private static final ThreadLocal<AddFlowInputBuilder> BUILDER = new ThreadLocal<AddFlowInputBuilder>() {
37 protected AddFlowInputBuilder initialValue() {
38 final AddFlowInputBuilder fb = new AddFlowInputBuilder();
43 final FlowCookie cookie = new FlowCookie(BigInteger.valueOf(10));
45 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));
56 protected void processPacket(final NodeKey node, final Match match, final Instructions instructions) {
57 final AddFlowInputBuilder fb = BUILDER.get();
59 // Finally build our flow
61 fb.setInstructions(instructions);
62 //fb.setId(new FlowId(Long.toString(fb.hashCode)));
64 // Construct the flow instance id
65 final InstanceIdentifier<Node> flowInstanceId = InstanceIdentifier
66 .builder(Nodes.class) // File under nodes
67 .child(Node.class, node).toInstance(); // A particular node identified by nodeKey
68 fb.setNode(new NodeRef(flowInstanceId));
71 flowService.addFlow(fb.build());