Bug 1544 - Explicit LLDP flow to punt whole LLDP packets to the controller
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / lldp / LLDPDataChangeListenerTest.java
1 /*
2  * Copyright (c) 2014 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.openflow.md.lldp;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13
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;
23
24 /**
25  * Created by Martin Bobak mbobak@cisco.com on 8/29/14.
26  */
27 public class LLDPDataChangeListenerTest {
28
29     @Mock
30     private static SalFlowService flowService;
31
32     /**
33      * Test method for {@link LLDPPAcketPuntEnforcer#createFlow()}
34      * which ensures that LLDPDataChangeListener creates proper flow for
35      */
36     @Test
37     public void testCreateFlow() {
38         LLDPPAcketPuntEnforcer lldpDataChangeListener = new LLDPPAcketPuntEnforcer(flowService);
39         evaluateFlow(lldpDataChangeListener.createFlow());
40     }
41
42     private final void evaluateFlow(Flow flow) {
43         evaluateInstructions(flow.getInstructions());
44     }
45
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);
51     }
52
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);
60         }
61     }
62
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());
68         }
69     }
70 }