use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class CzechLightFlowRuleProgrammable method getFlowEntries.
@Override
public Collection<FlowEntry> getFlowEntries() {
if (deviceType() == CzechLightDiscovery.DeviceType.INLINE_AMP || deviceType() == CzechLightDiscovery.DeviceType.COHERENT_ADD_DROP) {
final var data = getConnectionCache().get(data().deviceId());
if (data == null) {
return new ArrayList<>();
}
return data.stream().map(rule -> new DefaultFlowEntry(rule)).collect(Collectors.toList());
}
HierarchicalConfiguration xml;
try {
xml = doGetSubtree(CzechLightDiscovery.CHANNEL_DEFS_FILTER + CzechLightDiscovery.MC_ROUTING_FILTER);
} catch (NetconfException e) {
log.error("Cannot read data from NETCONF: {}", e);
return new ArrayList<>();
}
final var allChannels = MediaChannelDefinition.parseChannelDefinitions(xml);
Collection<FlowEntry> list = new ArrayList<>();
final var allMCs = xml.configurationsAt("data.media-channels");
allMCs.stream().map(cfg -> confToMCRouting(ELEMENT_ADD, allChannels, cfg)).filter(Objects::nonNull).forEach(flow -> {
log.debug("{}: found ADD: {}", data().deviceId(), flow.toString());
list.add(new DefaultFlowEntry(asFlowRule(Direction.ADD, flow), FlowEntry.FlowEntryState.ADDED));
});
allMCs.stream().map(cfg -> confToMCRouting(ELEMENT_DROP, allChannels, cfg)).filter(Objects::nonNull).forEach(flow -> {
log.debug("{}: found DROP: {}", data().deviceId(), flow.toString());
list.add(new DefaultFlowEntry(asFlowRule(Direction.DROP, flow), FlowEntry.FlowEntryState.ADDED));
});
return list;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class TelemetryVflowListCommand method doExecute.
@Override
protected void doExecute() {
CoreService coreService = get(CoreService.class);
FlowRuleService flowService = get(FlowRuleService.class);
ApplicationId appId = coreService.getAppId(OPENSTACK_TELEMETRY_APP_ID);
List<FlowEntry> flows = Lists.newArrayList(flowService.getFlowEntriesById(appId));
print(FORMAT, "SrcIp", "SrcPort", "DstIp", "DstPort", "Protocol");
for (FlowEntry entry : flows) {
TrafficSelector selector = entry.selector();
IpPrefix srcIp = ((IPCriterion) selector.getCriterion(IPV4_SRC)).ip();
IpPrefix dstIp = ((IPCriterion) selector.getCriterion(IPV4_DST)).ip();
TpPort srcPort = TpPort.tpPort(0);
TpPort dstPort = TpPort.tpPort(0);
String protocolStr = "ANY";
Criterion ipProtocolCriterion = selector.getCriterion(IP_PROTO);
if (ipProtocolCriterion != null) {
short protocol = ((IPProtocolCriterion) selector.getCriterion(IP_PROTO)).protocol();
if (protocol == PROTOCOL_TCP) {
srcPort = ((TcpPortCriterion) selector.getCriterion(TCP_SRC)).tcpPort();
dstPort = ((TcpPortCriterion) selector.getCriterion(TCP_DST)).tcpPort();
protocolStr = TCP;
}
if (protocol == PROTOCOL_UDP) {
srcPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
dstPort = ((UdpPortCriterion) selector.getCriterion(UDP_SRC)).udpPort();
protocolStr = UDP;
}
}
print(FORMAT, srcIp.toString(), srcPort.toString(), dstIp.toString(), dstPort.toString(), protocolStr);
}
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class FlowRuleManagerTest method flowMetrics.
@Test
public void flowMetrics() {
FlowRule f1 = flowRule(1, 1);
FlowRule f2 = flowRule(2, 2);
FlowRule f3 = flowRule(3, 3);
mgr.applyFlowRules(f1, f2, f3);
FlowEntry fe1 = new DefaultFlowEntry(f1);
FlowEntry fe2 = new DefaultFlowEntry(f2);
// FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED);
// FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED);
providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2));
assertTrue("Entries should be added.", validateState(ImmutableMap.of(f1, FlowEntryState.ADDED, f2, FlowEntryState.ADDED, f3, FlowEntryState.PENDING_ADD)));
validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_ADD_REQUESTED);
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class FlowRuleManagerTest method purgeFlowRules.
@Test
public void purgeFlowRules() {
FlowRule f1 = addFlowRule(1);
FlowRule f2 = addFlowRule(2);
FlowRule f3 = addFlowRule(3);
assertEquals("3 rules should exist", 3, flowCount());
FlowEntry fe1 = new DefaultFlowEntry(f1);
FlowEntry fe2 = new DefaultFlowEntry(f2);
FlowEntry fe3 = new DefaultFlowEntry(f3);
providerService.pushFlowMetrics(DID, ImmutableList.of(fe1, fe2, fe3));
validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_ADDED);
mgr.purgeFlowRules(DID);
assertEquals("0 rule should exist", 0, flowCount());
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class FlowRuleManagerTest method flowMissingRemove.
/*
* Tests whether a rule that was marked for removal but no flowRemoved was received
* is indeed removed at the next stats update.
*/
@Test
public void flowMissingRemove() {
FlowRule f1 = flowRule(1, 1);
FlowRule f2 = flowRule(2, 2);
FlowRule f3 = flowRule(3, 3);
// FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED);
// FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED);
FlowEntry fe1 = new DefaultFlowEntry(f1);
FlowEntry fe2 = new DefaultFlowEntry(f2);
mgr.applyFlowRules(f1, f2, f3);
mgr.removeFlowRules(f3);
providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2));
validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_REMOVE_REQUESTED, RULE_ADDED, RULE_ADDED, RULE_REMOVED);
}
Aggregations