Search in sources :

Example 1 with DeleteRulesCriteria

use of org.openkilda.messaging.command.switches.DeleteRulesCriteria in project open-kilda by telstra.

the class SwitchManagerTest method shouldDeleteRuleByInPort.

@Test
public void shouldDeleteRuleByInPort() throws Exception {
    // given
    final int testInPort = 11;
    expect(ofSwitchService.getActiveSwitch(dpid)).andStubReturn(iofSwitch);
    expect(iofSwitch.getOFFactory()).andStubReturn(ofFactory);
    mockFlowStatsRequest(cookie, DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
    Capture<OFFlowMod> capture = EasyMock.newCapture(CaptureType.ALL);
    expect(iofSwitch.write(capture(capture))).andReturn(true).times(3);
    mockBarrierRequest();
    mockFlowStatsRequest(DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
    expectLastCall();
    replay(ofSwitchService, iofSwitch);
    // when
    DeleteRulesCriteria criteria = DeleteRulesCriteria.builder().inPort(testInPort).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).egressSwitchId(SWITCH_ID).build();
    List<Long> deletedRules = switchManager.deleteRulesByCriteria(dpid, false, null, criteria);
    // then
    final OFFlowMod actual = capture.getValue();
    assertEquals(OFFlowModCommand.DELETE, actual.getCommand());
    assertEquals(testInPort, actual.getMatch().get(MatchField.IN_PORT).getPortNumber());
    assertNull(actual.getMatch().get(MatchField.VLAN_VID));
    assertEquals("any", actual.getOutPort().toString());
    assertEquals(0, actual.getInstructions().size());
    assertEquals(0L, actual.getCookie().getValue());
    assertEquals(0L, actual.getCookieMask().getValue());
    assertThat(deletedRules, containsInAnyOrder(cookie));
}
Also used : EasyMock.anyLong(org.easymock.EasyMock.anyLong) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Test(org.junit.Test)

Example 2 with DeleteRulesCriteria

use of org.openkilda.messaging.command.switches.DeleteRulesCriteria in project open-kilda by telstra.

the class SwitchManagerTest method shouldDeleteRuleByCookie.

@Test
public void shouldDeleteRuleByCookie() throws Exception {
    // given
    expect(ofSwitchService.getActiveSwitch(dpid)).andStubReturn(iofSwitch);
    expect(iofSwitch.getOFFactory()).andStubReturn(ofFactory);
    mockFlowStatsRequest(cookie, DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
    Capture<OFFlowMod> capture = EasyMock.newCapture(CaptureType.ALL);
    expect(iofSwitch.write(capture(capture))).andReturn(true).times(3);
    mockBarrierRequest();
    mockFlowStatsRequest(DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
    expectLastCall();
    replay(ofSwitchService, iofSwitch);
    // when
    DeleteRulesCriteria criteria = DeleteRulesCriteria.builder().cookie(cookie).build();
    List<Long> deletedRules = switchManager.deleteRulesByCriteria(dpid, false, null, criteria);
    // then
    final OFFlowMod actual = capture.getValue();
    assertEquals(OFFlowModCommand.DELETE, actual.getCommand());
    assertNull(actual.getMatch().get(MatchField.IN_PORT));
    assertNull(actual.getMatch().get(MatchField.VLAN_VID));
    assertEquals("any", actual.getOutPort().toString());
    assertEquals(0, actual.getInstructions().size());
    assertEquals(cookie, actual.getCookie().getValue());
    assertEquals(U64.NO_MASK, actual.getCookieMask());
    assertThat(deletedRules, containsInAnyOrder(cookie));
}
Also used : EasyMock.anyLong(org.easymock.EasyMock.anyLong) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Test(org.junit.Test)

Example 3 with DeleteRulesCriteria

use of org.openkilda.messaging.command.switches.DeleteRulesCriteria in project open-kilda by telstra.

the class SwitchManagerTest method shouldDeleteRuleByInPortVlanAndPriority.

@Test
public void shouldDeleteRuleByInPortVlanAndPriority() throws Exception {
    // given
    final int testInPort = 11;
    final short testInVlan = 101;
    final int testPriority = 999;
    expect(ofSwitchService.getActiveSwitch(dpid)).andStubReturn(iofSwitch);
    expect(iofSwitch.getOFFactory()).andStubReturn(ofFactory);
    mockFlowStatsRequest(cookie, DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
    Capture<OFFlowMod> capture = EasyMock.newCapture(CaptureType.ALL);
    expect(iofSwitch.write(capture(capture))).andReturn(true).times(3);
    mockBarrierRequest();
    mockFlowStatsRequest(DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
    expectLastCall();
    replay(ofSwitchService, iofSwitch);
    // when
    DeleteRulesCriteria criteria = DeleteRulesCriteria.builder().inPort(testInPort).encapsulationId((int) testInVlan).priority(testPriority).encapsulationType(FlowEncapsulationType.TRANSIT_VLAN).egressSwitchId(SWITCH_ID).build();
    List<Long> deletedRules = switchManager.deleteRulesByCriteria(dpid, false, null, criteria);
    // then
    final OFFlowMod actual = capture.getValue();
    assertEquals(OFFlowModCommand.DELETE, actual.getCommand());
    assertEquals(testInPort, actual.getMatch().get(MatchField.IN_PORT).getPortNumber());
    assertEquals(testInVlan, actual.getMatch().get(MatchField.VLAN_VID).getVlan());
    assertEquals("any", actual.getOutPort().toString());
    assertEquals(0, actual.getInstructions().size());
    assertEquals(0L, actual.getCookie().getValue());
    assertEquals(0L, actual.getCookieMask().getValue());
    assertEquals(testPriority, actual.getPriority());
    assertThat(deletedRules, containsInAnyOrder(cookie));
}
Also used : EasyMock.anyLong(org.easymock.EasyMock.anyLong) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Test(org.junit.Test)

Example 4 with DeleteRulesCriteria

use of org.openkilda.messaging.command.switches.DeleteRulesCriteria in project open-kilda by telstra.

the class SwitchManagerTest method shouldDeleteRuleByInPortAndVxlanTunnel.

@Test
public void shouldDeleteRuleByInPortAndVxlanTunnel() throws Exception {
    // given
    final int testInPort = 11;
    final short testInVlan = 101;
    expect(ofSwitchService.getActiveSwitch(dpid)).andStubReturn(iofSwitch);
    expect(iofSwitch.getOFFactory()).andStubReturn(ofFactory);
    mockFlowStatsRequest(cookie, DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
    Capture<OFFlowMod> capture = EasyMock.newCapture(CaptureType.ALL);
    expect(iofSwitch.write(capture(capture))).andReturn(true).times(3);
    mockBarrierRequest();
    mockFlowStatsRequest(DROP_RULE_COOKIE, VERIFICATION_BROADCAST_RULE_COOKIE, VERIFICATION_UNICAST_RULE_COOKIE);
    expectLastCall();
    replay(ofSwitchService, iofSwitch);
    // when
    DeleteRulesCriteria criteria = DeleteRulesCriteria.builder().inPort(testInPort).encapsulationId((int) testInVlan).encapsulationType(FlowEncapsulationType.VXLAN).egressSwitchId(SWITCH_ID).build();
    List<Long> deletedRules = switchManager.deleteRulesByCriteria(dpid, false, null, criteria);
    // then
    final OFFlowMod actual = capture.getValue();
    assertEquals(OFFlowModCommand.DELETE, actual.getCommand());
    assertEquals(testInPort, actual.getMatch().get(MatchField.IN_PORT).getPortNumber());
    assertEquals(testInVlan, actual.getMatch().get(MatchField.TUNNEL_ID).getValue());
    assertEquals("any", actual.getOutPort().toString());
    assertEquals(0, actual.getInstructions().size());
    assertEquals(0L, actual.getCookie().getValue());
    assertEquals(0L, actual.getCookieMask().getValue());
    assertThat(deletedRules, containsInAnyOrder(cookie));
}
Also used : EasyMock.anyLong(org.easymock.EasyMock.anyLong) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) OFFlowMod(org.projectfloodlight.openflow.protocol.OFFlowMod) Test(org.junit.Test)

Example 5 with DeleteRulesCriteria

use of org.openkilda.messaging.command.switches.DeleteRulesCriteria in project open-kilda by telstra.

the class CommandBuilderImplTest method shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithStringOutPort.

@Test
public void shouldBuildRemoveFlowWithoutMeterFromFlowEntryWithStringOutPort() {
    Long cookie = new FlowSegmentCookie(FlowPathDirection.FORWARD, 1).getValue();
    String inPort = "1";
    String inVlan = "10";
    String outPort = "in_port";
    FlowEntry flowEntry = buildFlowEntry(cookie, inPort, inVlan, outPort, null, false, null, null);
    RemoveFlow removeFlow = commandBuilder.buildRemoveFlowWithoutMeterFromFlowEntry(SWITCH_ID_A, flowEntry);
    assertEquals(cookie, removeFlow.getCookie());
    DeleteRulesCriteria criteria = removeFlow.getCriteria();
    assertEquals(cookie, criteria.getCookie());
    assertEquals(Integer.valueOf(inPort), criteria.getInPort());
    assertEquals(Integer.valueOf(inVlan), criteria.getEncapsulationId());
    assertNull(criteria.getOutPort());
    assertNull(criteria.getMetadataValue());
    assertNull(criteria.getMetadataMask());
}
Also used : FlowSegmentCookie(org.openkilda.model.cookie.FlowSegmentCookie) RemoveFlow(org.openkilda.messaging.command.flow.RemoveFlow) DeleteRulesCriteria(org.openkilda.messaging.command.switches.DeleteRulesCriteria) FlowEntry(org.openkilda.messaging.info.rule.FlowEntry) Test(org.junit.Test)

Aggregations

DeleteRulesCriteria (org.openkilda.messaging.command.switches.DeleteRulesCriteria)17 Test (org.junit.Test)13 OFFlowMod (org.projectfloodlight.openflow.protocol.OFFlowMod)10 EasyMock.anyLong (org.easymock.EasyMock.anyLong)9 SwitchOperationException (org.openkilda.floodlight.error.SwitchOperationException)3 UnsupportedSwitchOperationException (org.openkilda.floodlight.error.UnsupportedSwitchOperationException)3 RemoveFlow (org.openkilda.messaging.command.flow.RemoveFlow)3 FlowEntry (org.openkilda.messaging.info.rule.FlowEntry)3 FlowEncapsulationType (org.openkilda.model.FlowEncapsulationType)3 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ArrayList (java.util.ArrayList)2 SwitchNotFoundException (org.openkilda.floodlight.error.SwitchNotFoundException)2 IKafkaProducerService (org.openkilda.floodlight.service.kafka.IKafkaProducerService)2 DatapathId (org.projectfloodlight.openflow.types.DatapathId)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1