3de499753386b4aef6becb9ca9fbb9cb493ba766
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / experimenter / AbstractBundleMessageFactoryTest.java
1 /*
2  * Copyright (c) 2016 Pantheon Technologies s.r.o. 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.openflowjava.protocol.impl.serialization.experimenter;
10
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.UnpooledByteBufAllocator;
13 import java.util.ArrayList;
14 import java.util.Collections;
15 import java.util.List;
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundleFlags;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.BundlePropertyType;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.BundleProperty;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.BundlePropertyBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.bundle.property.bundle.property.entry.BundleExperimenterPropertyBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.bundle.properties.bundle.property.bundle.property.entry.bundle.experimenter.property.BundleExperimenterPropertyData;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.bundle.add.message.message.PortModCase;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.approved.extensions.rev160802.experimenter.input.experimenter.data.of.choice.bundle.add.message.message.PortModCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ExperimenterId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortConfig;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortFeatures;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
32 import org.opendaylight.yangtools.yang.binding.DataContainer;
33
34 /**
35  * Test for {@link org.opendaylight.openflowjava.protocol.impl.serialization.experimenter.AbstractBundleMessageFactory}
36  * and util methods.
37  */
38 public class AbstractBundleMessageFactoryTest {
39
40     @Test
41     public void writeBundleFlags() throws Exception {
42         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
43         AbstractBundleMessageFactory.writeBundleFlags(new BundleFlags(true, true), out);
44         Assert.assertEquals("Wrong flags", 3, out.readUnsignedShort());
45     }
46
47     public static List<BundleProperty> createListWithBundleExperimenterProperty(BundleExperimenterPropertyData data) {
48         BundlePropertyBuilder propertyBuilder = new BundlePropertyBuilder();
49         propertyBuilder.setType(BundlePropertyType.ONFETBPTEXPERIMENTER);
50         BundleExperimenterPropertyBuilder experimenterPropertyBuilder = new BundleExperimenterPropertyBuilder();
51         experimenterPropertyBuilder.setExperimenter(new ExperimenterId(1L));
52         experimenterPropertyBuilder.setExpType(2L);
53
54         experimenterPropertyBuilder.setBundleExperimenterPropertyData(data);
55         propertyBuilder.setBundlePropertyEntry(experimenterPropertyBuilder.build());
56         return new ArrayList<>(Collections.singleton(propertyBuilder.build()));
57     }
58
59     public static BundleExperimenterPropertyData createBundleExperimenterPropertyData() {
60         return new BundleExperimenterPropertyData() {
61             @Override
62             public Class<? extends DataContainer> getImplementedInterface() {
63                 return null;
64             }
65         };
66     }
67
68     public static PortModCase createPortModCase() {
69         PortModCaseBuilder caseBuilder = new PortModCaseBuilder();
70         caseBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
71         caseBuilder.setXid(3L);
72         caseBuilder.setPortNo(new PortNumber(9L));
73         caseBuilder.setHwAddress(new MacAddress("08:00:27:00:B0:EB"));
74         caseBuilder.setConfig(new PortConfig(true, false, true, false));
75         caseBuilder.setMask(new PortConfig(false, true, false, true));
76         caseBuilder.setAdvertise(new PortFeatures(true, false, false, false,
77                 false, false, false, true,
78                 false, false, false, false,
79                 false, false, false, false));
80         return caseBuilder.build();
81     }
82 }