2 * Copyright (c) 2014 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
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesKey;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
13 import test.mock.util.SalTableServiceMock;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeaturesBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.table.features.TableFeatures;
16 import org.junit.Test;
17 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
19 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
20 import org.opendaylight.openflowplugin.applications.frm.impl.ForwardingRulesManagerImpl;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
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 test.mock.util.FRMTest;
30 import test.mock.util.RpcProviderRegistryMock;
31 import java.util.List;
32 import static org.junit.Assert.assertEquals;
34 public class TableFeaturesListenerTest extends FRMTest {
35 RpcProviderRegistry rpcProviderRegistryMock = new RpcProviderRegistryMock();
38 public void updateFlowTest() throws Exception {
39 NodeKey s1Key = new NodeKey(new NodeId("S1"));
40 TableKey tableKey = new TableKey((short) 2);
41 TableFeaturesKey tableFeaturesKey = new TableFeaturesKey(tableKey.getId());
42 ForwardingRulesManagerImpl forwardingRulesManager = new ForwardingRulesManagerImpl(getDataBroker(), rpcProviderRegistryMock);
43 forwardingRulesManager.start();
45 addTable(tableKey, s1Key);
47 TableFeatures tableFeaturesData = new TableFeaturesBuilder().setKey(tableFeaturesKey).build();
48 InstanceIdentifier<TableFeatures> tableFeaturesII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
49 .augmentation(FlowCapableNode.class).child(Table.class, tableKey).child(TableFeatures.class, tableFeaturesKey);
50 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
51 writeTx.put(LogicalDatastoreType.CONFIGURATION, tableFeaturesII, tableFeaturesData);
52 assertCommit(writeTx.submit());
54 tableFeaturesData = new TableFeaturesBuilder().setKey(tableFeaturesKey).setName("dummy name").build();
55 writeTx = getDataBroker().newWriteOnlyTransaction();
56 writeTx.put(LogicalDatastoreType.CONFIGURATION, tableFeaturesII, tableFeaturesData);
57 assertCommit(writeTx.submit());
59 SalTableServiceMock salTableServiceMock = (SalTableServiceMock) forwardingRulesManager.getSalTableService();
60 List<UpdateTableInput> updateTableInputs = salTableServiceMock.getUpdateTableInput();
61 assertEquals(1, updateTableInputs.size());
62 assertEquals("DOM-0", updateTableInputs.get(0).getTransactionUri().getValue());
64 forwardingRulesManager.close();