Merge "BUG:5888 - Changing FRM from clustered DCN to clustered DTCN"
[openflowplugin.git] / applications / forwardingrules-sync / src / test / java / org / opendaylight / openflowplugin / applications / frsync / impl / strategy / DiffInputFactory.java
1 /**
2  * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.applications.frsync.impl.strategy;
10
11 import org.opendaylight.openflowplugin.applications.frsync.util.ItemSyncBox;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
21
22 /**
23  * Provides create methods for data involved in {@link SynchronizationDiffInput}.
24  */
25 public class DiffInputFactory {
26     static ItemSyncBox<Group> createGroupSyncBox(final long... groupIDs) {
27         final ItemSyncBox<Group> groupBox = new ItemSyncBox<>();
28
29         for (long gid : groupIDs) {
30             groupBox.getItemsToPush().add(createPlainGroup(gid));
31         }
32         return groupBox;
33     }
34
35     static ItemSyncBox<Group> createGroupSyncBoxWithUpdates(final long... groupIDs) {
36         final ItemSyncBox<Group> groupBox = new ItemSyncBox<>();
37
38         for (long gid : groupIDs) {
39             groupBox.getItemsToPush().add(createPlainGroup(gid));
40             groupBox.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(createPlainGroup(gid + 50),
41                     createPlainGroup(gid + 100)));
42         }
43         return groupBox;
44     }
45
46     private static Group createPlainGroup(final long gid) {
47         return new GroupBuilder().setGroupId(new GroupId(gid)).build();
48     }
49
50     static ItemSyncBox<Meter> createMeterSyncBox(final long... meterIDs) {
51         final ItemSyncBox<Meter> groupBox = new ItemSyncBox<>();
52
53         for (long gid : meterIDs) {
54             groupBox.getItemsToPush().add(createPlainMeter(gid));
55         }
56         return groupBox;
57     }
58
59     static ItemSyncBox<Meter> createMeterSyncBoxWithUpdates(final long... meterIDs) {
60         final ItemSyncBox<Meter> groupBox = new ItemSyncBox<>();
61
62         for (long mid : meterIDs) {
63             groupBox.getItemsToPush().add(createPlainMeter(mid));
64             groupBox.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(createPlainMeter(mid + 50),
65                     createPlainMeter(mid + 100)));
66         }
67         return groupBox;
68     }
69
70     private static Meter createPlainMeter(final long mid) {
71         return new MeterBuilder().setMeterId(new MeterId(mid)).build();
72     }
73
74     static ItemSyncBox<Flow> createFlowSyncBox(final String... flowIDs) {
75         final ItemSyncBox<Flow> flowBox = new ItemSyncBox<>();
76
77         for (String fid : flowIDs) {
78             flowBox.getItemsToPush().add(createPlainFlow(fid));
79         }
80         return flowBox;
81     }
82
83     static ItemSyncBox<Flow> createFlowSyncBoxWithUpdates(final String... flowIDs) {
84         final ItemSyncBox<Flow> groupBox = new ItemSyncBox<>();
85
86         for (String fid : flowIDs) {
87             groupBox.getItemsToPush().add(createPlainFlow(fid));
88             groupBox.getItemsToUpdate().add(new ItemSyncBox.ItemUpdateTuple<>(createPlainFlow(fid + "orig"),
89                     createPlainFlow(fid + "upd")));
90         }
91         return groupBox;
92     }
93
94     private static Flow createPlainFlow(final String fid) {
95         return new FlowBuilder().setId(new FlowId(fid)).build();
96     }
97 }