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.md.sal.binding.api.WriteTransaction;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
14 import org.opendaylight.openflowplugin.applications.frm.impl.ForwardingRulesManagerImpl;
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.*;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import test.mock.util.FRMTest;
28 import test.mock.util.RpcProviderRegistryMock;
29 import test.mock.util.SalGroupServiceMock;
31 import java.util.List;
33 import static org.junit.Assert.assertEquals;
35 public class GroupListenerTest extends FRMTest {
36 RpcProviderRegistry rpcProviderRegistryMock = new RpcProviderRegistryMock();
37 NodeKey s1Key = new NodeKey(new NodeId("S1"));
40 public void addTwoGroupsTest() throws Exception {
41 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(
79 rpcProviderRegistryMock,
81 forwardingRulesManager.start();
83 addFlowCapableNode(s1Key);
85 GroupKey groupKey = new GroupKey(new GroupId((long) 255));
86 InstanceIdentifier<Group> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
87 .augmentation(FlowCapableNode.class).child(Group.class, groupKey);
88 Group group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build();
90 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
91 writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
92 assertCommit(writeTx.submit());
93 SalGroupServiceMock salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
94 List<AddGroupInput> addGroupCalls = salGroupService.getAddGroupCalls();
95 assertEquals(1, addGroupCalls.size());
96 assertEquals("DOM-0", addGroupCalls.get(0).getTransactionUri().getValue());
98 group = new GroupBuilder().setKey(groupKey).setGroupName("Group2").build();
99 writeTx = getDataBroker().newWriteOnlyTransaction();
100 writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
101 assertCommit(writeTx.submit());
102 salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
103 List<UpdateGroupInput> updateGroupCalls = salGroupService.getUpdateGroupCalls();
104 assertEquals(1, updateGroupCalls.size());
105 assertEquals("DOM-1", updateGroupCalls.get(0).getTransactionUri().getValue());
107 forwardingRulesManager.close();
111 public void removeGroupTest() throws Exception {
112 ForwardingRulesManagerImpl forwardingRulesManager = new ForwardingRulesManagerImpl(
114 rpcProviderRegistryMock,
116 forwardingRulesManager.start();
118 addFlowCapableNode(s1Key);
120 GroupKey groupKey = new GroupKey(new GroupId((long) 255));
121 InstanceIdentifier<Group> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
122 .augmentation(FlowCapableNode.class).child(Group.class, groupKey);
123 Group group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build();
125 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
126 writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
127 assertCommit(writeTx.submit());
128 SalGroupServiceMock salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
129 List<AddGroupInput> addGroupCalls = salGroupService.getAddGroupCalls();
130 assertEquals(1, addGroupCalls.size());
131 assertEquals("DOM-0", addGroupCalls.get(0).getTransactionUri().getValue());
133 writeTx = getDataBroker().newWriteOnlyTransaction();
134 writeTx.delete(LogicalDatastoreType.CONFIGURATION, groupII);
135 assertCommit(writeTx.submit());
136 salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
137 List<RemoveGroupInput> removeGroupCalls = salGroupService.getRemoveGroupCalls();
138 assertEquals(1, removeGroupCalls.size());
139 assertEquals("DOM-1", removeGroupCalls.get(0).getTransactionUri().getValue());
141 forwardingRulesManager.close();
145 public void staleGroupCreationTest() throws Exception {
146 addFlowCapableNode(s1Key);
148 StaleGroupKey groupKey = new StaleGroupKey(new GroupId((long) 255));
149 InstanceIdentifier<StaleGroup> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
150 .augmentation(FlowCapableNode.class).child(StaleGroup.class, groupKey);
151 StaleGroup group = new StaleGroupBuilder().setKey(groupKey).setGroupName("Stale_Group1").build();
153 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
154 writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
155 assertCommit(writeTx.submit());