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.applications.tableMissEnforcer;
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.openflowplugin.applications.tableMissEnforcer.LLDPPacketPuntEnforcer;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.Instructions;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.ApplyActionsCase;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
26 * Created by Martin Bobak mbobak@cisco.com on 8/29/14.
28 public class LLDPDataChangeListenerTest {
31 private static SalFlowService flowService;
34 * Test method for {@link org.opendaylight.openflowplugin.applications.tableMissEnforcer.LLDPPacketPuntEnforcer#createFlow()}
35 * which ensures that LLDPDataChangeListener creates proper flow for
38 public void testCreateFlow() {
39 LLDPPacketPuntEnforcer lldpDataChangeListener = new LLDPPacketPuntEnforcer(flowService);
40 evaluateFlow(lldpDataChangeListener.createFlow());
43 private final void evaluateFlow(Flow flow) {
44 evaluateInstructions(flow.getInstructions());
47 private final void evaluateInstructions(Instructions instructions) {
48 assertNotNull(instructions.getInstruction());
49 assertEquals(1, instructions.getInstruction().size());
50 Instruction instruction = instructions.getInstruction().get(0);
51 evaluateInstruction(instruction);
54 private final void evaluateInstruction(Instruction instruction) {
55 if (instruction.getInstruction() instanceof ApplyActionsCase) {
56 ApplyActionsCase applyActionsCase = (ApplyActionsCase) instruction.getInstruction();
57 assertNotNull(applyActionsCase.getApplyActions().getAction());
58 assertEquals(1, applyActionsCase.getApplyActions().getAction().size());
59 Action action = applyActionsCase.getApplyActions().getAction().get(0);
60 evaluateAction(action);
64 private final void evaluateAction(Action action) {
65 if (action.getAction() instanceof OutputActionCase) {
66 OutputActionCase outputActionCase = (OutputActionCase) action.getAction();
67 assertEquals("CONTROLLER", outputActionCase.getOutputAction().getOutputNodeConnector().getValue());
68 assertEquals(new Integer(0xffff).intValue(), outputActionCase.getOutputAction().getMaxLength().intValue());