@Test public void testExecuteforLogicalTunnel() throws ActionException { LogicalPort ltIface = createLogicalTunnelPort("lt-1/2/0", 12); ltIface = addVlanToIface(ltIface, 2); setVlanAction.setParams(ltIface); ActionResponse response = setVlanAction.execute(protocolSessionManager); Assert.assertEquals(ActionConstants.SET_VLANID, response.getActionID()); List<Response> responses = response.getResponses(); for (Response resp : responses) { Assert.assertEquals(Response.Status.OK, resp.getStatus()); } // FIXME This test fails due to mock router not filering config // setEncapsulationAction.setParams(ltIface); // response = setEncapsulationAction.execute(protocolSessionManager); // Assert.assertEquals(ActionConstants.SET_TAGGEDETHERNET_ENCAPSULATION, // response.getActionID()); // responses = response.getResponses(); // for (Response resp : responses) { // Assert.assertEquals(Response.Status.OK, resp.getStatus()); // } removeEncapsulationAction.setParams(ltIface); response = removeEncapsulationAction.execute(protocolSessionManager); Assert.assertEquals( ActionConstants.REMOVE_TAGGEDETHERNET_ENCAPSULATION, response.getActionID()); responses = response.getResponses(); for (Response resp : responses) { Assert.assertEquals(Response.Status.OK, resp.getStatus()); } }
@BeforeClass public static void init() { setEncapsulationAction = new SetTaggedEthernetEncapsulationAction(); removeEncapsulationAction = new RemoveTaggedEthernetEncapsulationAction(); setVlanAction = new SetVlanIdAction(); setEncapsulationAction.setModelToUpdate(new ComputerSystem()); removeEncapsulationAction.setModelToUpdate(new ComputerSystem()); setVlanAction.setModelToUpdate(new ComputerSystem()); protocolManager = new ProtocolManager(); try { protocolSessionManager = (ProtocolSessionManager) protocolManager.getProtocolSessionManager(resourceId); protocolSessionManager.setEventManager(new MockEventManager()); netconfContext = newSessionContextNetconf(); protocolManager.sessionFactoryAdded( new NetconfProtocolSessionFactory(), new HashMap<String, String>() { { put(ProtocolSessionContext.PROTOCOL, "netconf"); } }); protocolSessionManager.registerContext(netconfContext); } catch (ProtocolException e) { e.printStackTrace(); } }
@Test public void TestActionID() { Assert.assertEquals( ActionConstants.SET_TAGGEDETHERNET_ENCAPSULATION, setEncapsulationAction.getActionID()); Assert.assertEquals( ActionConstants.REMOVE_TAGGEDETHERNET_ENCAPSULATION, removeEncapsulationAction.getActionID()); Assert.assertEquals(ActionConstants.SET_VLANID, setVlanAction.getActionID()); }
/** * TODO, it is necessary to implement the dummy state to configure vlans * * @throws ActionException */ @Test public void testExecuteforETH() throws ActionException { LogicalPort feIface = createEthernetPort("fe-0/3/2", 4); feIface = addVlanToIface(feIface, 3); setVlanAction.setParams(feIface); ActionResponse response = setVlanAction.execute(protocolSessionManager); Assert.assertEquals(ActionConstants.SET_VLANID, response.getActionID()); List<Response> responses = response.getResponses(); for (Response resp : responses) { Assert.assertEquals(Response.Status.OK, resp.getStatus()); } // An interface with vlan-tagging and subinterfaces with vlans LogicalPort phyFeIface = createPhysicalInterface("fe-0/1/3"); // FIXME This test fails due to mock router not filering config // setEncapsulationAction.setParams(phyFeIface); // response = setEncapsulationAction.execute(protocolSessionManager); // Assert.assertEquals(ActionConstants.SET_TAGGEDETHERNET_ENCAPSULATION, // response.getActionID()); // responses = response.getResponses(); // for (Response resp : responses) { // Assert.assertEquals(Response.Status.OK, resp.getStatus()); // } try { removeEncapsulationAction.setParams(phyFeIface); response = removeEncapsulationAction.execute(protocolSessionManager); // Assert.assertEquals(ActionConstants.REMOVE_TAGGEDETHERNET_ENCAPSULATION, // response.getActionID()); // responses = response.getResponses(); // for (Response resp : responses) { // Assert.assertEquals(Response.Status.OK, resp.getStatus()); // } } catch (ActionException e) { Assert.assertTrue( e.getLocalizedMessage() .contains( "Interface has subinterfaces with vlanId. Please remove them before changing encapsulation.")); } }
@Test public void checkParamsTest() throws ActionException { LogicalPort phyFeIface = createPhysicalInterface("fe-0/3/1"); LogicalPort phyLtIface = createPhysicalInterface("lt-1/2/0"); LogicalPort feIface = createEthernetPort("fe-0/3/1", 2); LogicalPort ltIface = createLogicalTunnelPort("lt-1/2/0", 2); Assert.assertTrue(setEncapsulationAction.checkParams(phyFeIface)); Assert.assertTrue(setEncapsulationAction.checkParams(ltIface)); Assert.assertTrue(removeEncapsulationAction.checkParams(phyFeIface)); Assert.assertTrue(removeEncapsulationAction.checkParams(ltIface)); try { setEncapsulationAction.checkParams(phyLtIface); Assert.fail("SetTaggedEthEncapsulation on physical lt interface should fail"); } catch (ActionException e) { } try { setEncapsulationAction.checkParams(feIface); Assert.fail("SetTaggedEthEncapsulation on logical fe interface should fail"); } catch (ActionException e) { } try { removeEncapsulationAction.checkParams(phyLtIface); Assert.fail("RemoveTaggedEthEncapsulation on physical lt interface should fail"); } catch (ActionException e) { } try { removeEncapsulationAction.checkParams(feIface); Assert.fail("RemoveTaggedEthEncapsulation on logical fe interface should fail"); } catch (ActionException e) { } try { setVlanAction.checkParams(phyFeIface); Assert.fail("Set vlanid action on physical interface should fail"); } catch (ActionException e) { } try { setVlanAction.checkParams(phyLtIface); Assert.fail("Set vlanid action on physical interface should fail"); } catch (ActionException e) { } try { setVlanAction.checkParams(feIface); Assert.fail("Set vlanid action without vlan should fail"); } catch (ActionException e) { } try { setVlanAction.checkParams(ltIface); Assert.fail("Set vlanid action without vlan should fail"); } catch (ActionException e) { } // add vlans phyFeIface = addVlanToIface(phyFeIface, 12); phyLtIface = addVlanToIface(phyLtIface, 12); feIface = addVlanToIface(feIface, 12); ltIface = addVlanToIface(ltIface, 12); try { setVlanAction.checkParams(phyFeIface); Assert.fail("Set vlanid action on physical interface should fail"); } catch (ActionException e) { } try { setVlanAction.checkParams(phyLtIface); Assert.fail("Set vlanid action on physical interface should fail"); } catch (ActionException e) { } Assert.assertTrue(setVlanAction.checkParams(feIface)); Assert.assertTrue(setVlanAction.checkParams(ltIface)); // use invalid vlans LogicalPort feIface2 = createEthernetPort("fe-0/3/1", 2); LogicalPort ltIface2 = createLogicalTunnelPort("lt-1/2/0", 2); feIface2 = addVlanToIface(feIface2, 8888); ltIface2 = addVlanToIface(ltIface2, 8888); try { setVlanAction.checkParams(feIface2); Assert.fail("Set vlanid action with invalid vlan id should fail"); } catch (ActionException e) { } try { setVlanAction.checkParams(ltIface2); Assert.fail("Set vlanid action with invalid vlan id should fail"); } catch (ActionException e) { } }