2 * Copyright (c) 2015 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.openflowplugin.impl.registry.flow;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotEquals;
14 import java.math.BigInteger;
15 import java.util.ArrayList;
16 import java.util.HashSet;
17 import java.util.List;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.openflowplugin.api.openflow.registry.flow.FlowHash;
21 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev100924.MacAddress;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdateBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapList;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.and.statistics.map.list.FlowAndStatisticsMapListBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowCookie;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetDestinationBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.ethernet.match.fields.EthernetSourceBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.EthernetMatchBuilder;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class FlowHashFactoryTest {
36 private static final Logger LOG = LoggerFactory.getLogger(FlowHashFactoryTest.class);
39 private static final FlowsStatisticsUpdateBuilder FLOWS_STATISTICS_UPDATE_BUILDER = new FlowsStatisticsUpdateBuilder();
44 List<FlowAndStatisticsMapList> flowAndStatisticsMapListList = new ArrayList();
45 for (int i = 1; i < 4; i++) {
46 FlowAndStatisticsMapListBuilder flowAndStatisticsMapListBuilder = new FlowAndStatisticsMapListBuilder();
47 flowAndStatisticsMapListBuilder.setPriority(i);
48 flowAndStatisticsMapListBuilder.setTableId((short) i);
49 flowAndStatisticsMapListBuilder.setCookie(new FlowCookie(BigInteger.TEN));
51 MatchBuilder matchBuilder = new MatchBuilder();
53 EthernetMatchBuilder ethernetMatchBuilder = new EthernetMatchBuilder();
55 EthernetSourceBuilder ethernetSourceBuilder = new EthernetSourceBuilder();
56 MacAddress macAddress = new MacAddress("00:00:00:00:00:0" + i);
57 ethernetSourceBuilder.setAddress(macAddress);
58 ethernetMatchBuilder.setEthernetSource(ethernetSourceBuilder.build());
60 EthernetDestinationBuilder ethernetDestinationBuilder = new EthernetDestinationBuilder();
61 ethernetDestinationBuilder.setAddress(new MacAddress("00:00:00:0" + i + ":00:00"));
62 ethernetMatchBuilder.setEthernetDestination(ethernetDestinationBuilder.build());
64 matchBuilder.setEthernetMatch(ethernetMatchBuilder.build());
66 flowAndStatisticsMapListBuilder.setMatch(matchBuilder.build());
67 flowAndStatisticsMapListList.add(flowAndStatisticsMapListBuilder.build());
69 FLOWS_STATISTICS_UPDATE_BUILDER.setFlowAndStatisticsMapList(flowAndStatisticsMapListList);
73 public void testEquals() throws Exception {
74 FlowsStatisticsUpdate flowStats = FLOWS_STATISTICS_UPDATE_BUILDER.build();
76 HashSet<FlowHash> flowHashs = new HashSet();
77 for (FlowAndStatisticsMapList item : flowStats.getFlowAndStatisticsMapList()) {
78 FlowHash flowHash = FlowHashFactory.create(item);
79 flowHashs.add(flowHash);
80 flowHashs.add(flowHash);
82 assertEquals(3, flowHashs.size());
86 public void testGetHash() throws Exception {
87 FlowsStatisticsUpdate flowStats = FLOWS_STATISTICS_UPDATE_BUILDER.build();
89 for (FlowAndStatisticsMapList item : flowStats.getFlowAndStatisticsMapList()) {
90 FlowHash flowHash = FlowHashFactory.create(item);
91 FlowHash lastHash = null;
92 if (null != lastHash) {
93 assertNotEquals(lastHash, flowHash);