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.clustering.EntityOwnershipService;
13 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
14 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
15 import org.opendaylight.openflowplugin.applications.frm.impl.ForwardingRulesManagerImpl;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.*;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import test.mock.util.EntityOwnershipServiceMock;
29 import test.mock.util.FRMTest;
30 import test.mock.util.RpcProviderRegistryMock;
31 import test.mock.util.SalGroupServiceMock;
33 import java.util.List;
35 import static org.junit.Assert.assertEquals;
37 public class GroupListenerTest extends FRMTest {
38 RpcProviderRegistry rpcProviderRegistryMock = new RpcProviderRegistryMock();
39 EntityOwnershipService eos = new EntityOwnershipServiceMock();
41 NodeKey s1Key = new NodeKey(new NodeId("S1"));
44 public void addTwoGroupsTest() throws Exception {
45 ForwardingRulesManagerImpl forwardingRulesManager = new ForwardingRulesManagerImpl(getDataBroker(), rpcProviderRegistryMock,
47 forwardingRulesManager.start();
49 addFlowCapableNode(s1Key);
51 GroupKey groupKey = new GroupKey(new GroupId((long) 255));
52 InstanceIdentifier<Group> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
53 .augmentation(FlowCapableNode.class).child(Group.class, groupKey);
54 Group group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build();
56 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
57 writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
58 assertCommit(writeTx.submit());
59 SalGroupServiceMock salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
60 List<AddGroupInput> addGroupCalls = salGroupService.getAddGroupCalls();
61 assertEquals(1, addGroupCalls.size());
62 assertEquals("DOM-0", addGroupCalls.get(0).getTransactionUri().getValue());
64 groupKey = new GroupKey(new GroupId((long) 256));
65 groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
66 .augmentation(FlowCapableNode.class).child(Group.class, groupKey);
67 group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build();
68 writeTx = getDataBroker().newWriteOnlyTransaction();
69 writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
70 assertCommit(writeTx.submit());
71 salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
72 addGroupCalls = salGroupService.getAddGroupCalls();
73 assertEquals(2, addGroupCalls.size());
74 assertEquals("DOM-1", addGroupCalls.get(1).getTransactionUri().getValue());
76 forwardingRulesManager.close();
80 public void updateGroupTest() throws Exception {
81 ForwardingRulesManagerImpl forwardingRulesManager = new ForwardingRulesManagerImpl(
83 rpcProviderRegistryMock,
85 forwardingRulesManager.start();
87 addFlowCapableNode(s1Key);
89 GroupKey groupKey = new GroupKey(new GroupId((long) 255));
90 InstanceIdentifier<Group> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
91 .augmentation(FlowCapableNode.class).child(Group.class, groupKey);
92 Group group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build();
94 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
95 writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
96 assertCommit(writeTx.submit());
97 SalGroupServiceMock salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
98 List<AddGroupInput> addGroupCalls = salGroupService.getAddGroupCalls();
99 assertEquals(1, addGroupCalls.size());
100 assertEquals("DOM-0", addGroupCalls.get(0).getTransactionUri().getValue());
102 group = new GroupBuilder().setKey(groupKey).setGroupName("Group2").build();
103 writeTx = getDataBroker().newWriteOnlyTransaction();
104 writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
105 assertCommit(writeTx.submit());
106 salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
107 List<UpdateGroupInput> updateGroupCalls = salGroupService.getUpdateGroupCalls();
108 assertEquals(1, updateGroupCalls.size());
109 assertEquals("DOM-1", updateGroupCalls.get(0).getTransactionUri().getValue());
111 forwardingRulesManager.close();
115 public void removeGroupTest() throws Exception {
116 ForwardingRulesManagerImpl forwardingRulesManager = new ForwardingRulesManagerImpl(
118 rpcProviderRegistryMock,
120 forwardingRulesManager.start();
122 addFlowCapableNode(s1Key);
124 GroupKey groupKey = new GroupKey(new GroupId((long) 255));
125 InstanceIdentifier<Group> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
126 .augmentation(FlowCapableNode.class).child(Group.class, groupKey);
127 Group group = new GroupBuilder().setKey(groupKey).setGroupName("Group1").build();
129 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
130 writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
131 assertCommit(writeTx.submit());
132 SalGroupServiceMock salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
133 List<AddGroupInput> addGroupCalls = salGroupService.getAddGroupCalls();
134 assertEquals(1, addGroupCalls.size());
135 assertEquals("DOM-0", addGroupCalls.get(0).getTransactionUri().getValue());
137 writeTx = getDataBroker().newWriteOnlyTransaction();
138 writeTx.delete(LogicalDatastoreType.CONFIGURATION, groupII);
139 assertCommit(writeTx.submit());
140 salGroupService = (SalGroupServiceMock) forwardingRulesManager.getSalGroupService();
141 List<RemoveGroupInput> removeGroupCalls = salGroupService.getRemoveGroupCalls();
142 assertEquals(1, removeGroupCalls.size());
143 assertEquals("DOM-1", removeGroupCalls.get(0).getTransactionUri().getValue());
145 forwardingRulesManager.close();
149 public void staleGroupCreationTest() throws Exception {
150 addFlowCapableNode(s1Key);
152 StaleGroupKey groupKey = new StaleGroupKey(new GroupId((long) 255));
153 InstanceIdentifier<StaleGroup> groupII = InstanceIdentifier.create(Nodes.class).child(Node.class, s1Key)
154 .augmentation(FlowCapableNode.class).child(StaleGroup.class, groupKey);
155 StaleGroup group = new StaleGroupBuilder().setKey(groupKey).setGroupName("Stale_Group1").build();
157 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
158 writeTx.put(LogicalDatastoreType.CONFIGURATION, groupII, group);
159 assertCommit(writeTx.submit());