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
9 package org.opendaylight.controller.md.statistics.manager;
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Prefix;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4Match;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv4MatchBuilder;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
22 public class StatisticsUpdateCommiterTest {
24 private static final Logger LOG = LoggerFactory
25 .getLogger(StatisticsUpdateCommiterTest.class);
28 * Test method for {@link org.opendaylight.controller.md.statistics.manager.StatisticsUpdateCommiter#layer3MatchEquals(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match, org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Layer3Match)}.
31 public void testLayer3MatchEquals() {
32 String[][][] matchSeeds = new String[][][] {
33 {{"10.1.2.0/24", "10.1.2.0/24"}, {"10.1.2.0/24", "10.1.2.0/24"}},
34 {{"10.1.2.0/24", "10.1.2.0/24"}, {"10.1.2.0/24", "10.1.1.0/24"}},
35 {{"10.1.1.0/24", "10.1.2.0/24"}, {"10.1.2.0/24", "10.1.2.0/24"}},
36 {{"10.1.1.0/24", "10.1.1.0/24"}, {"10.1.2.0/24", "10.1.2.0/24"}},
38 {{"10.1.1.0/24", null}, {"10.1.1.0/24", "10.1.2.0/24"}},
39 {{"10.1.1.0/24", null}, {"10.1.2.0/24", "10.1.2.0/24"}},
40 {{"10.1.1.0/24", null}, {"10.1.2.0/24", null}},
41 {{"10.1.1.0/24", null}, {"10.1.1.0/24", null}},
43 {{null, "10.1.1.0/24"}, {"10.1.2.0/24", "10.1.1.0/24"}},
44 {{null, "10.1.1.0/24"}, {"10.1.2.0/24", "10.1.2.0/24"}},
45 {{null, "10.1.1.0/24"}, {null, "10.1.2.0/24"}},
46 {{null, "10.1.1.0/24"}, {null, "10.1.1.0/24"}},
48 {{null, null}, {null, "10.1.1.0/24"}},
49 {{null, null}, {null, null}},
52 boolean[] matches = new boolean[] {
72 for (int i = 0; i < matches.length; i++) {
73 checkComparisonOfL3Match(
74 matchSeeds[i][0][0], matchSeeds[i][0][1],
75 matchSeeds[i][1][0], matchSeeds[i][1][1],
81 * @param m1Source match1 - src
82 * @param m1Destination match1 - dest
83 * @param m2Source match2 - src
84 * @param msDestination match2 - dest
85 * @param matches expected match output
88 private static void checkComparisonOfL3Match(String m1Source, String m1Destination,
89 String m2Source, String msDestination, boolean matches) {
90 Ipv4Match m1Layer3 = prepareIPv4Match(m1Source, m1Destination);
91 Ipv4Match m2Layer3 = prepareIPv4Match(m2Source, msDestination);
92 boolean comparisonResult;
94 comparisonResult = StatisticsUpdateCommiter.layer3MatchEquals(m1Layer3, m2Layer3);
95 Assert.assertEquals("failed to compare: "+m1Layer3+" vs. "+m2Layer3,
96 matches, comparisonResult);
97 } catch (Exception e) {
98 LOG.error("failed to compare: {} vs. {}", m1Layer3, m2Layer3, e);
99 Assert.fail(e.getMessage());
103 private static Ipv4Match prepareIPv4Match(String source, String destination) {
104 Ipv4MatchBuilder ipv4MatchBuilder = new Ipv4MatchBuilder();
105 if (source != null) {
106 ipv4MatchBuilder.setIpv4Source(new Ipv4Prefix(source));
108 if (destination != null) {
109 ipv4MatchBuilder.setIpv4Destination(new Ipv4Prefix(destination));
112 return ipv4MatchBuilder.build();