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.openflowplugin.openflow.md.lldp;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
14 import org.junit.Test;
15 import org.mockito.Mock;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
25 * Created by Martin Bobak mbobak@cisco.com on 8/29/14.
27 public class LLDPDataChangeListenerTest {
30 private static SalFlowService flowService;
33 * Test method for {@link LLDPPAcketPuntEnforcer#createFlow()}
34 * which ensures that LLDPDataChangeListener creates proper flow for
37 public void testCreateFlow() {
38 LLDPPAcketPuntEnforcer lldpDataChangeListener = new LLDPPAcketPuntEnforcer(flowService);
39 evaluateFlow(lldpDataChangeListener.createFlow());
42 private final void evaluateFlow(Flow flow) {
43 evaluateInstructions(flow.getInstructions());
46 private final void evaluateInstructions(Instructions instructions) {
47 assertNotNull(instructions.getInstruction());
48 assertEquals(1, instructions.getInstruction().size());
49 Instruction instruction = instructions.getInstruction().get(0);
50 evaluateInstruction(instruction);
53 private final void evaluateInstruction(Instruction instruction) {
54 if (instruction.getInstruction() instanceof ApplyActionsCase) {
55 ApplyActionsCase applyActionsCase = (ApplyActionsCase) instruction.getInstruction();
56 assertNotNull(applyActionsCase.getApplyActions().getAction());
57 assertEquals(1, applyActionsCase.getApplyActions().getAction().size());
58 Action action = applyActionsCase.getApplyActions().getAction().get(0);
59 evaluateAction(action);
63 private final void evaluateAction(Action action) {
64 if (action.getAction() instanceof OutputActionCase) {
65 OutputActionCase outputActionCase = (OutputActionCase) action.getAction();
66 assertEquals("CONTROLLER", outputActionCase.getOutputAction().getOutputNodeConnector().getValue());
67 assertEquals(new Integer(0xffff).intValue(), outputActionCase.getOutputAction().getMaxLength().intValue());