Search in sources :

Example 16 with MeterId

use of org.openkilda.model.MeterId in project open-kilda by telstra.

the class ValidationServiceImplTest method validateMetersProperMeters.

@Test
public void validateMetersProperMeters() {
    ValidationService validationService = new ValidationServiceImpl(persistenceManager().build());
    MeterSpeakerData meter = MeterSpeakerData.builder().meterId(new MeterId(32)).rate(10000).burst(10500).ofVersion(OfVersion.OF_13).flags(Sets.newHashSet(MeterFlag.KBPS, MeterFlag.BURST, MeterFlag.STATS)).build();
    ValidateMetersResult response = validationService.validateMeters(SWITCH_ID_B, singletonList(meter), singletonList(meter));
    assertTrue(response.getMissingMeters().isEmpty());
    assertTrue(response.getMisconfiguredMeters().isEmpty());
    assertFalse(response.getProperMeters().isEmpty());
    assertEquals(meter.getMeterId().getValue(), response.getProperMeters().get(0).getMeterId().longValue());
    assertMeter(response.getProperMeters().get(0), 32, 10000, 10500, new String[] { "KBPS", "BURST", "STATS" });
    assertTrue(response.getExcessMeters().isEmpty());
}
Also used : MeterSpeakerData(org.openkilda.rulemanager.MeterSpeakerData) ValidateMetersResult(org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult) ValidationService(org.openkilda.wfm.topology.switchmanager.service.ValidationService) MeterId(org.openkilda.model.MeterId) Test(org.junit.Test)

Example 17 with MeterId

use of org.openkilda.model.MeterId in project open-kilda by telstra.

the class UniCastDiscoveryRuleGenerator method generateCommands.

@Override
public List<SpeakerData> generateCommands(Switch sw) {
    List<SpeakerData> commands = new ArrayList<>();
    Instructions instructions = Instructions.builder().applyActions(new ArrayList<>()).build();
    FlowSpeakerData flowCommand = buildRule(sw, instructions);
    if (flowCommand == null) {
        return Collections.emptyList();
    } else {
        commands.add(flowCommand);
    }
    MeterId meterId = createMeterIdForDefaultRule(VERIFICATION_UNICAST_RULE_COOKIE);
    SpeakerData meterCommand = generateMeterCommandForServiceRule(sw, meterId, config.getUnicastRateLimit(), config.getSystemMeterBurstSizeInPackets(), config.getDiscoPacketSize());
    if (meterCommand != null) {
        commands.add(meterCommand);
        addMeterToInstructions(meterId, sw, instructions);
    }
    instructions.getApplyActions().add(new PortOutAction(new PortNumber(SpecialPortType.CONTROLLER)));
    // todo remove useless set field action
    instructions.getApplyActions().add(SetFieldAction.builder().field(Field.ETH_DST).value(sw.getSwitchId().toLong()).build());
    if (meterCommand != null) {
        flowCommand.getDependsOn().add(meterCommand.getUuid());
    }
    return commands;
}
Also used : FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) PortOutAction(org.openkilda.rulemanager.action.PortOutAction) ArrayList(java.util.ArrayList) Instructions(org.openkilda.rulemanager.Instructions) PortNumber(org.openkilda.rulemanager.ProtoConstants.PortNumber) SpeakerData(org.openkilda.rulemanager.SpeakerData) FlowSpeakerData(org.openkilda.rulemanager.FlowSpeakerData) MeterId(org.openkilda.model.MeterId)

Example 18 with MeterId

use of org.openkilda.model.MeterId in project open-kilda by telstra.

the class SwitchValidateServiceImplTest method setUp.

@Before
public void setUp() {
    RepositoryFactory repositoryFactory = Mockito.mock(RepositoryFactory.class);
    FlowPathRepository flowPathRepository = Mockito.mock(FlowPathRepository.class);
    SwitchRepository switchRepository = Mockito.mock(SwitchRepository.class);
    when(switchRepository.findById(eq(SWITCH_ID))).thenReturn(Optional.of(SWITCH_1));
    when(switchRepository.findById(eq(SWITCH_ID_MISSING))).thenReturn(Optional.empty());
    LagLogicalPortRepository lagLogicalPortRepository = Mockito.mock(LagLogicalPortRepository.class);
    when(repositoryFactory.createFlowPathRepository()).thenReturn(flowPathRepository);
    when(repositoryFactory.createSwitchRepository()).thenReturn(switchRepository);
    when(persistenceManager.getRepositoryFactory()).thenReturn(repositoryFactory);
    service = new SwitchValidateServiceImpl(carrier, persistenceManager, validationService, ruleManager);
    request = SwitchValidateRequest.builder().switchId(SWITCH_ID).processMeters(true).build();
    flowSpeakerData = FlowSpeakerData.builder().ofVersion(OfVersion.OF_13).cookie(new Cookie(1L)).table(OfTable.INPUT).priority(10).match(emptySet()).instructions(Instructions.builder().build()).flags(emptySet()).build();
    meterSpeakerData = MeterSpeakerData.builder().meterId(new MeterId(32)).rate(10000).burst(10500).ofVersion(OfVersion.OF_13).flags(Sets.newHashSet(MeterFlag.KBPS, MeterFlag.BURST, MeterFlag.STATS)).build();
    when(validationService.validateRules(any(), any(), any())).thenReturn(new ValidateRulesResult(newHashSet(flowSpeakerData.getCookie().getValue()), emptySet(), emptySet(), emptySet()));
    when(validationService.validateMeters(any(), any(), any())).thenReturn(new ValidateMetersResult(emptyList(), emptyList(), emptyList(), emptyList()));
}
Also used : LagLogicalPortRepository(org.openkilda.persistence.repositories.LagLogicalPortRepository) Cookie(org.openkilda.model.cookie.Cookie) FlowPathRepository(org.openkilda.persistence.repositories.FlowPathRepository) ValidateRulesResult(org.openkilda.wfm.topology.switchmanager.model.ValidateRulesResult) ValidateMetersResult(org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult) SwitchRepository(org.openkilda.persistence.repositories.SwitchRepository) RepositoryFactory(org.openkilda.persistence.repositories.RepositoryFactory) MeterId(org.openkilda.model.MeterId) Before(org.junit.Before)

Example 19 with MeterId

use of org.openkilda.model.MeterId in project open-kilda by telstra.

the class DatabaseSupportImpl method updateFlowMeterId.

@Override
public void updateFlowMeterId(String flowId, long newMeterId) {
    // TODO(andriidovhan) rewrite it, FlowPair flowPair -> Flow
    // FlowPair flowPair = flowPairRepository.findById(flowId)
    // .orElseThrow(() -> new RuntimeException(format("Unable to find Flow for %s", flowId)));
    // flowPair.getForward().setMeterId(newMeterId.getValue());
    // flowPair.getReverse().setMeterId(newMeterId.getValue());
    // flowRepository.createOrUpdate(flowPair);
    // flow path
    transactionManager.doInTransaction(() -> {
        Collection<FlowPath> flowPaths = flowPathRepository.findByFlowId(flowId);
        long meterId = newMeterId;
        for (FlowPath flowPath : flowPaths) {
            flowPath.setMeterId(new MeterId(meterId));
            Optional<FlowMeter> meter = flowMeterRepository.findByPathId(flowPath.getPathId());
            if (meter.isPresent()) {
                meter.get().setMeterId(new MeterId(meterId++));
            }
        }
    });
}
Also used : FlowPath(org.openkilda.model.FlowPath) FlowMeter(org.openkilda.model.FlowMeter) MeterId(org.openkilda.model.MeterId)

Example 20 with MeterId

use of org.openkilda.model.MeterId in project open-kilda by telstra.

the class RuleManagerImpl method buildIngressYFlowCommands.

private List<SpeakerData> buildIngressYFlowCommands(FlowPath flowPath, FlowPath altFlowPath, DataAdapter adapter) {
    Flow flow = adapter.getFlow(flowPath.getPathId());
    Flow altFlow = adapter.getFlow(altFlowPath.getPathId());
    if (flow.isProtectedPath(flowPath.getPathId()) || altFlow.isProtectedPath(altFlowPath.getPathId())) {
        return Collections.emptyList();
    }
    YFlow yFlow = adapter.getYFlow(flowPath.getPathId());
    if (yFlow == null) {
        return Collections.emptyList();
    }
    SwitchId sharedSwitchId = yFlow.getSharedEndpoint().getSwitchId();
    Switch sharedSwitch = adapter.getSwitch(sharedSwitchId);
    if (sharedSwitch == null || !sharedSwitchId.equals(flowPath.getSrcSwitchId()) || !sharedSwitchId.equals(altFlowPath.getSrcSwitchId())) {
        return Collections.emptyList();
    }
    FlowTransitEncapsulation encapsulation = getFlowTransitEncapsulation(flowPath.getPathId(), flow, adapter);
    FlowTransitEncapsulation altEncapsulation = getFlowTransitEncapsulation(altFlowPath.getPathId(), altFlow, adapter);
    MeterId sharedMeterId = yFlow.getSharedEndpointMeterId();
    RuleGenerator generator = flowRulesFactory.getIngressYRuleGenerator(flowPath, flow, encapsulation, new HashSet<>(), altFlowPath, altFlow, altEncapsulation, new HashSet<>(), sharedMeterId);
    return generator.generateCommands(sharedSwitch);
}
Also used : YFlow(org.openkilda.model.YFlow) Switch(org.openkilda.model.Switch) FlowTransitEncapsulation(org.openkilda.model.FlowTransitEncapsulation) SwitchId(org.openkilda.model.SwitchId) RuleGenerator(org.openkilda.rulemanager.factory.RuleGenerator) Flow(org.openkilda.model.Flow) YFlow(org.openkilda.model.YFlow) MeterId(org.openkilda.model.MeterId)

Aggregations

MeterId (org.openkilda.model.MeterId)62 PathId (org.openkilda.model.PathId)20 Flow (org.openkilda.model.Flow)19 FlowPath (org.openkilda.model.FlowPath)18 FlowSegmentCookie (org.openkilda.model.cookie.FlowSegmentCookie)18 Test (org.junit.Test)17 SwitchId (org.openkilda.model.SwitchId)16 Switch (org.openkilda.model.Switch)11 ArrayList (java.util.ArrayList)10 PathSegment (org.openkilda.model.PathSegment)9 MeterSpeakerData (org.openkilda.rulemanager.MeterSpeakerData)7 List (java.util.List)6 ValidateMetersResult (org.openkilda.wfm.topology.switchmanager.model.ValidateMetersResult)6 FlowMeter (org.openkilda.model.FlowMeter)5 MeterConfig (org.openkilda.model.MeterConfig)5 YFlow (org.openkilda.model.YFlow)5 Instructions (org.openkilda.rulemanager.Instructions)5 PortOutAction (org.openkilda.rulemanager.action.PortOutAction)5 ValidationService (org.openkilda.wfm.topology.switchmanager.service.ValidationService)5 MessageContext (org.openkilda.messaging.MessageContext)4