use of org.onosproject.net.behaviour.upf.UpfEntity in project up4 by omec-project.
the class ReadUpfEntitiesCommand method doExecute.
@Override
protected void doExecute() {
Up4AdminService up4Admin = get(Up4AdminService.class);
Up4Service up4Service = get(Up4Service.class);
boolean filterCounters = false;
try {
List<UpfEntityType> printedTypes = new ArrayList<>();
if (all) {
printedTypes.add(UpfEntityType.APPLICATION);
printedTypes.add(UpfEntityType.SESSION_UPLINK);
printedTypes.add(UpfEntityType.SESSION_DOWNLINK);
printedTypes.add(UpfEntityType.TERMINATION_UPLINK);
printedTypes.add(UpfEntityType.TERMINATION_DOWNLINK);
printedTypes.add(UpfEntityType.TUNNEL_PEER);
printedTypes.add(UpfEntityType.INTERFACE);
printedTypes.add(UpfEntityType.SESSION_METER);
printedTypes.add(UpfEntityType.APPLICATION_METER);
filterCounters = true;
} else if (ue) {
printedTypes.add(UpfEntityType.APPLICATION);
printedTypes.add(UpfEntityType.SESSION_UPLINK);
printedTypes.add(UpfEntityType.SESSION_DOWNLINK);
printedTypes.add(UpfEntityType.TERMINATION_UPLINK);
printedTypes.add(UpfEntityType.TERMINATION_DOWNLINK);
printedTypes.add(UpfEntityType.TUNNEL_PEER);
printedTypes.add(UpfEntityType.SESSION_METER);
printedTypes.add(UpfEntityType.APPLICATION_METER);
filterCounters = true;
} else {
if (application) {
printedTypes.add(UpfEntityType.APPLICATION);
}
if (sessions) {
printedTypes.add(UpfEntityType.SESSION_UPLINK);
printedTypes.add(UpfEntityType.SESSION_DOWNLINK);
}
if (termination) {
printedTypes.add(UpfEntityType.TERMINATION_UPLINK);
printedTypes.add(UpfEntityType.TERMINATION_DOWNLINK);
}
if (tunnels) {
printedTypes.add(UpfEntityType.TUNNEL_PEER);
}
if (counters) {
printedTypes.add(UpfEntityType.COUNTER);
filterCounters = false;
}
if (interfaces) {
printedTypes.add(UpfEntityType.INTERFACE);
}
if (appMeters) {
printedTypes.add(UpfEntityType.APPLICATION_METER);
}
if (sessMeters) {
printedTypes.add(UpfEntityType.SESSION_METER);
}
}
for (var type : printedTypes) {
if (type.equals(UpfEntityType.TERMINATION_UPLINK)) {
Collection<? extends UpfEntity> terminations = up4Admin.adminReadAll(type);
for (var t : terminations) {
UpfTerminationUplink term = (UpfTerminationUplink) t;
print(term.toString());
if (filterCounters) {
print(up4Service.readCounter(term.counterId()).toString());
}
}
} else if (type.equals(UpfEntityType.TERMINATION_DOWNLINK)) {
Collection<? extends UpfEntity> terminations = up4Admin.adminReadAll(type);
for (var t : terminations) {
UpfTerminationDownlink term = (UpfTerminationDownlink) t;
print(term.toString());
if (filterCounters) {
print(up4Service.readCounter(term.counterId()).toString());
}
}
} else {
up4Admin.adminReadAll(type).forEach(upfEntity -> print(upfEntity.toString()));
}
}
} catch (UpfProgrammableException e) {
print("Error while reading UPF entity: " + e.getMessage());
}
}
use of org.onosproject.net.behaviour.upf.UpfEntity in project up4 by omec-project.
the class Up4DeviceManager method getUplinkFlows.
@Override
public Collection<UplinkUpfFlow> getUplinkFlows() throws UpfProgrammableException {
Collection<UplinkUpfFlow> uplinkFlows = Lists.newArrayList();
Collection<? extends UpfEntity> uplinkTerm = this.adminReadAll(TERMINATION_UPLINK);
Map<Integer, UpfMeter> appMeters = Maps.newHashMap();
this.adminReadAll(APPLICATION_METER).forEach(am -> appMeters.put(((UpfMeter) am).cellId(), (UpfMeter) am));
for (UpfEntity t : uplinkTerm) {
UpfTerminationUplink term = (UpfTerminationUplink) t;
uplinkFlows.add(UplinkUpfFlow.builder().withTerminationUplink(term).withCounter(this.readCounter(term.counterId())).withAppMeter(appMeters.getOrDefault(term.appMeterIdx(), null)).build());
}
return uplinkFlows;
}
use of org.onosproject.net.behaviour.upf.UpfEntity in project up4 by omec-project.
the class Up4TranslatorImplTest method up4ToUpfEntity.
public UpfEntity up4ToUpfEntity(UpfEntity expected, PiEntity up4Entry) {
UpfEntity translatedEntity;
try {
switch(up4Entry.piEntityType()) {
case TABLE_ENTRY:
translatedEntity = up4Translator.up4TableEntryToUpfEntity((PiTableEntry) up4Entry);
break;
case METER_CELL_CONFIG:
translatedEntity = up4Translator.up4MeterEntryToUpfEntity((PiMeterCellConfig) up4Entry);
break;
default:
assertThat("Unsupported PI entity!", false);
return null;
}
} catch (Up4Translator.Up4TranslationException e) {
assertThat("UP4 table entry should translate to UPF entity without error.", false);
return null;
}
assertThat(translatedEntity, equalTo(expected));
return translatedEntity;
}
use of org.onosproject.net.behaviour.upf.UpfEntity in project up4 by omec-project.
the class ReadFlowsCommand method doExecute.
@Override
protected void doExecute() throws Exception {
Up4AdminService adminService = get(Up4AdminService.class);
Collection<DownlinkUpfFlow> dlUpfFlow = adminService.getDownlinkFlows();
Collection<UplinkUpfFlow> ulUpfFlow = adminService.getUplinkFlows();
Collection<? extends UpfEntity> ulSess = adminService.adminReadAll(UpfEntityType.SESSION_UPLINK);
Collection<? extends UpfEntity> appFilters = adminService.adminReadAll(UpfEntityType.APPLICATION);
// Get session and app meter only to show the number of meters
Collection<? extends UpfEntity> sessMeters = adminService.adminReadAll(UpfEntityType.SESSION_METER);
Map<Integer, UpfMeter> sessMeterMap = sessMeters.stream().map(m -> (UpfMeter) m).collect(Collectors.toMap(UpfMeter::cellId, m -> m));
Collection<? extends UpfEntity> appMeters = adminService.adminReadAll(UpfEntityType.APPLICATION_METER);
print(SEPARATOR);
print(appFilters.size() + " Applications");
for (UpfEntity a : appFilters) {
if (!a.type().equals(UpfEntityType.APPLICATION)) {
print("ERROR: Wrong application filter: " + a);
continue;
}
UpfApplication app = (UpfApplication) a;
print("app_id=" + app.appId() + ", ipv4_prefix=" + app.ip4Prefix() + ", l4_range=" + app.l4PortRange() + ", ip_proto=" + app.ipProto());
}
print(SEPARATOR);
print(ulSess.size() + " Uplink Sessions");
for (UpfEntity s : ulSess) {
if (!s.type().equals(UpfEntityType.SESSION_UPLINK)) {
print("ERROR: Wrong uplink session: " + s);
continue;
}
UpfSessionUplink sess = (UpfSessionUplink) s;
print("n3_addr=" + sess.tunDstAddr() + ", teid=" + sess.teid() + (sess.needsDropping() ? ", drop()" : ", fwd(" + "sess_meter_idx=" + sess.sessionMeterIdx() + ")"));
UpfMeter sessMeter = sessMeterMap.getOrDefault(sess.sessionMeterIdx(), null);
if (sessMeter == null) {
print(" NO SESSION METER (sess_meter_idx=" + sess.sessionMeterIdx() + ")");
} else {
print(" Session meter: " + ppUpfMeter(sessMeter));
}
}
print(SEPARATOR);
print(ulUpfFlow.size() + " Uplink Flows");
for (UplinkUpfFlow f : ulUpfFlow) {
print(f.toString());
}
print(SEPARATOR);
print(dlUpfFlow.size() + " Downlink Flows");
for (DownlinkUpfFlow f : dlUpfFlow) {
print(f.toString());
}
print(SEPARATOR);
print("Apps=%d, UL sess=%d, UL flows=%d, DL flows=%s", appFilters.size(), ulSess.size(), ulUpfFlow.size(), dlUpfFlow.size());
print("App meters=%d, Sess meters=%d", appMeters.size(), sessMeters.size());
}
use of org.onosproject.net.behaviour.upf.UpfEntity in project up4 by omec-project.
the class Up4DeviceManager method getDownlinkFlows.
@Override
public Collection<DownlinkUpfFlow> getDownlinkFlows() throws UpfProgrammableException {
Collection<DownlinkUpfFlow> downlinkFlows = Lists.newArrayList();
Map<Ip4Address, UpfSessionDownlink> ueToSess = Maps.newHashMap();
Map<Byte, UpfGtpTunnelPeer> idToTunn = Maps.newHashMap();
Map<Integer, UpfMeter> sessMeters = Maps.newHashMap();
Map<Integer, UpfMeter> appMeters = Maps.newHashMap();
Collection<? extends UpfEntity> downlinkTerm = this.adminReadAll(TERMINATION_DOWNLINK);
this.adminReadAll(SESSION_DOWNLINK).forEach(s -> ueToSess.put(((UpfSessionDownlink) s).ueAddress(), (UpfSessionDownlink) s));
this.adminReadAll(TUNNEL_PEER).forEach(t -> idToTunn.put(((UpfGtpTunnelPeer) t).tunPeerId(), (UpfGtpTunnelPeer) t));
this.adminReadAll(SESSION_METER).forEach(sm -> sessMeters.put(((UpfMeter) sm).cellId(), (UpfMeter) sm));
this.adminReadAll(APPLICATION_METER).forEach(am -> appMeters.put(((UpfMeter) am).cellId(), (UpfMeter) am));
for (UpfEntity t : downlinkTerm) {
UpfTerminationDownlink term = (UpfTerminationDownlink) t;
UpfSessionDownlink sess = ueToSess.getOrDefault(term.ueSessionId(), null);
UpfGtpTunnelPeer tunn = null;
UpfMeter sMeter = null;
UpfMeter aMeter = null;
if (sess != null) {
tunn = idToTunn.getOrDefault(sess.tunPeerId(), null);
sMeter = sessMeters.getOrDefault(sess.sessionMeterIdx(), null);
}
aMeter = appMeters.getOrDefault(term.appMeterIdx(), null);
downlinkFlows.add(DownlinkUpfFlow.builder().withTerminationDownlink(term).withSessionDownlink(sess).withTunnelPeer(tunn).withCounter(this.readCounter(term.counterId())).withAppMeter(aMeter).withSessionMeter(sMeter).build());
}
return downlinkFlows;
}
Aggregations