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.junit.Test;
11 import org.opendaylight.controller.frm.impl.ForwardingRulesManagerImpl;
12 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
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 test.mock.util.FRMTest;
29 import test.mock.util.RpcProviderRegistryMock;
30 import test.mock.util.SalGroupServiceMock;
32 import java.util.List;
34 import static org.junit.Assert.assertEquals;
36 public class GroupListenerTest extends FRMTest {
37 RpcProviderRegistry rpcProviderRegistryMock = new RpcProviderRegistryMock();
38 NodeKey s1Key = new NodeKey(new NodeId("S1"));
41 public void addTwoGroupsTest() throws Exception {
42 ForwardingRulesManagerImpl forwardingRulesManager = new ForwardingRulesManagerImpl(getDataBroker(), rpcProviderRegistryMock);
43 forwardingRulesManager.start();
45 addFlowCapableNode(s1Key);
47 GroupKey groupKey = new GroupKey(new GroupId((long) 255));
48 InstanceIdentifier<Group> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
49 .augmentation(FlowCapableNode.class).child(Group.class, groupKey);
50 Group group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build();
52 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
53 writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
54 assertCommit(writeTx.submit());
55 SalGroupServiceMock salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
56 List<AddGroupInput> addGroupCalls = salGroupService.getAddGroupCalls();
57 assertEquals(1, addGroupCalls.size());
58 assertEquals("DOM-0", addGroupCalls.get(0).getTransactionUri().getValue());
60 groupKey = new GroupKey(new GroupId((long) 256));
61 groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
62 .augmentation(FlowCapableNode.class).child(Group.class, groupKey);
63 group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build();
64 writeTx = getDataBroker().newWriteOnlyTransaction();
65 writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
66 assertCommit(writeTx.submit());
67 salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
68 addGroupCalls = salGroupService.getAddGroupCalls();
69 assertEquals(2, addGroupCalls.size());
70 assertEquals("DOM-1", addGroupCalls.get(1).getTransactionUri().getValue());
72 forwardingRulesManager.close();
76 public void updateGroupTest() throws Exception {
77 ForwardingRulesManagerImpl forwardingRulesManager = new ForwardingRulesManagerImpl(getDataBroker(), rpcProviderRegistryMock);
78 forwardingRulesManager.start();
80 addFlowCapableNode(s1Key);
82 GroupKey groupKey = new GroupKey(new GroupId((long) 255));
83 InstanceIdentifier<Group> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
84 .augmentation(FlowCapableNode.class).child(Group.class, groupKey);
85 Group group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build();
87 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
88 writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
89 assertCommit(writeTx.submit());
90 SalGroupServiceMock salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
91 List<AddGroupInput> addGroupCalls = salGroupService.getAddGroupCalls();
92 assertEquals(1, addGroupCalls.size());
93 assertEquals("DOM-0", addGroupCalls.get(0).getTransactionUri().getValue());
95 group = new GroupBuilder().setKey(groupKey).setGroupName("Group2").build();
96 writeTx = getDataBroker().newWriteOnlyTransaction();
97 writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
98 assertCommit(writeTx.submit());
99 salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
100 List<UpdateGroupInput> updateGroupCalls = salGroupService.getUpdateGroupCalls();
101 assertEquals(1, updateGroupCalls.size());
102 assertEquals("DOM-1", updateGroupCalls.get(0).getTransactionUri().getValue());
104 forwardingRulesManager.close();
108 public void removeGroupTest() throws Exception {
109 ForwardingRulesManagerImpl forwardingRulesManager = new ForwardingRulesManagerImpl(getDataBroker(), rpcProviderRegistryMock);
110 forwardingRulesManager.start();
112 addFlowCapableNode(s1Key);
114 GroupKey groupKey = new GroupKey(new GroupId((long) 255));
115 InstanceIdentifier<Group> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
116 .augmentation(FlowCapableNode.class).child(Group.class, groupKey);
117 Group group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build();
119 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
120 writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
121 assertCommit(writeTx.submit());
122 SalGroupServiceMock salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
123 List<AddGroupInput> addGroupCalls = salGroupService.getAddGroupCalls();
124 assertEquals(1, addGroupCalls.size());
125 assertEquals("DOM-0", addGroupCalls.get(0).getTransactionUri().getValue());
127 writeTx = getDataBroker().newWriteOnlyTransaction();
128 writeTx.delete(LogicalDatastoreType.CONFIGURATION, groupII);
129 assertCommit(writeTx.submit());
130 salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
131 List<RemoveGroupInput> removeGroupCalls = salGroupService.getRemoveGroupCalls();
132 assertEquals(1, removeGroupCalls.size());
133 assertEquals("DOM-1", removeGroupCalls.get(0).getTransactionUri().getValue());
135 forwardingRulesManager.close();