org.onosproject.net.pi.model.PiPipeconf Java Examples
The following examples show how to use
org.onosproject.net.pi.model.PiPipeconf.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpectrumPipelineProgrammable.java From onos with Apache License 2.0 | 6 votes |
private ByteBuffer extensionBuffer(PiPipeconf pipeconf, ExtensionType extType) { if (!pipeconf.extension(extType).isPresent()) { log.warn("Missing extension {} in pipeconf {}", extType, pipeconf.id()); throw new ExtensionException(); } try { byte[] bytes = IOUtils.toByteArray(pipeconf.extension(extType).get()); // Length of the extension + bytes. return ByteBuffer.allocate(bytes.length) .order(ByteOrder.LITTLE_ENDIAN) .put(bytes); } catch (IOException ex) { log.warn("Unable to read extension {} from pipeconf {}: {}", extType, pipeconf.id(), ex.getMessage()); throw new ExtensionException(); } }
Example #2
Source File: AbstractCodec.java From onos with Apache License 2.0 | 6 votes |
/** * Encodes the given collection of objects. Throws an exception if one or * more of the given objects cannot be encoded. The returned list is * guaranteed to have same size and order as the given one. * * @param objects list of objects * @param metadata metadata * @param pipeconf pipeconf * @return list of protobuf messages * @throws CodecException if one or more of the given objects cannot be * encoded */ List<M> encodeAll(Collection<P> objects, X metadata, PiPipeconf pipeconf) throws CodecException { checkNotNull(objects); if (objects.isEmpty()) { return ImmutableList.of(); } final List<M> messages = encodeAllSkipException(objects, metadata, pipeconf); if (objects.size() != messages.size()) { throw new CodecException(format( "Unable to encode %d entities of %d given " + "(see previous logs for details)", objects.size() - messages.size(), objects.size())); } return messages; }
Example #3
Source File: TableEntryCodec.java From onos with Apache License 2.0 | 6 votes |
private PiTableAction decodeTableActionMsg( P4RuntimeOuterClass.TableAction tableActionMsg, PiPipeconf pipeconf) throws CodecException { P4RuntimeOuterClass.TableAction.TypeCase typeCase = tableActionMsg.getTypeCase(); switch (typeCase) { case ACTION: P4RuntimeOuterClass.Action actionMsg = tableActionMsg.getAction(); return CODECS.action().decode( actionMsg, null, pipeconf); case ACTION_PROFILE_GROUP_ID: return PiActionProfileGroupId.of( tableActionMsg.getActionProfileGroupId()); case ACTION_PROFILE_MEMBER_ID: return PiActionProfileMemberId.of( tableActionMsg.getActionProfileMemberId()); default: throw new CodecException( format("Decoding of table action type %s not implemented", typeCase.name())); } }
Example #4
Source File: TofinoPipelineProgrammable.java From onos with Apache License 2.0 | 6 votes |
@Override public ByteBuffer createDeviceDataBuffer(PiPipeconf pipeconf) { List<ByteBuffer> buffers = Lists.newLinkedList(); if (pipeconf.extension(RAW_DEVICE_CONFIG).isPresent()) { buffers.add(rawDeviceConfig(pipeconf)); } else { try { buffers.add(nameBuffer(pipeconf)); buffers.add(extensionBuffer(pipeconf, TOFINO_BIN)); buffers.add(extensionBuffer(pipeconf, TOFINO_CONTEXT_JSON)); } catch (ExtensionException e) { return null; } } // Concatenate buffers (flip so they can be read). int len = buffers.stream().mapToInt(Buffer::limit).sum(); ByteBuffer deviceData = ByteBuffer.allocate(len); buffers.forEach(b -> deviceData.put((ByteBuffer) b.flip())); deviceData.flip(); return deviceData.asReadOnlyBuffer(); }
Example #5
Source File: ActionProfileGroupCodec.java From onos with Apache License 2.0 | 6 votes |
@Override public PiActionProfileGroup decode( ActionProfileGroup msg, Object ignored, PiPipeconf pipeconf, P4InfoBrowser browser) throws P4InfoBrowser.NotFoundException { final PiActionProfileGroup.Builder piGroupBuilder = PiActionProfileGroup.builder() .withActionProfileId(PiActionProfileId.of( browser.actionProfiles() .getById(msg.getActionProfileId()) .getPreamble().getName())) .withId(PiActionProfileGroupId.of(msg.getGroupId())) .withMaxSize(msg.getMaxSize()); msg.getMembersList().forEach(m -> { final int weight; if (m.getWeight() < 1) { log.warn("Decoding group with invalid weight '{}', will set to 1", m.getWeight()); weight = 1; } else { weight = m.getWeight(); } piGroupBuilder.addMember( PiActionProfileMemberId.of(m.getMemberId()), weight); }); return piGroupBuilder.build(); }
Example #6
Source File: PipeconfHelper.java From onos with Apache License 2.0 | 6 votes |
/** * Extracts and returns a P4Info protobuf message from the given pipeconf. If the pipeconf does not define any * extension of type {@link PiPipeconf.ExtensionType#P4_INFO_TEXT}, returns null; * * @param pipeconf pipeconf * @return P4Info or null */ public static P4Info getP4Info(PiPipeconf pipeconf) { return P4INFOS.computeIfAbsent(pipeconf.fingerprint(), piPipeconfId -> { if (!pipeconf.extension(P4_INFO_TEXT).isPresent()) { log.warn("Missing P4Info extension in pipeconf {}", pipeconf.id()); return null; } InputStream p4InfoStream = pipeconf.extension(P4_INFO_TEXT).get(); P4Info.Builder p4iInfoBuilder = P4Info.newBuilder(); try { TextFormat.getParser().merge(new InputStreamReader(p4InfoStream), ExtensionRegistry.getEmptyRegistry(), p4iInfoBuilder); } catch (IOException ex) { log.warn("Unable to parse P4Info of pipeconf {}: {}", pipeconf.id(), ex.getMessage()); return null; } return p4iInfoBuilder.build(); }); }
Example #7
Source File: PipeconfHelper.java From onos with Apache License 2.0 | 6 votes |
/** * Returns a P4Info browser for the given pipeconf. If the pipeconf does not define any extension of type * {@link PiPipeconf.ExtensionType#P4_INFO_TEXT}, returns null; * * @param pipeconf pipeconf * @return P4Info browser or null */ public static P4InfoBrowser getP4InfoBrowser(PiPipeconf pipeconf) { try { return BROWSERS.get(pipeconf.fingerprint(), () -> { P4Info p4info = PipeconfHelper.getP4Info(pipeconf); if (p4info == null) { return null; } else { return new P4InfoBrowser(p4info); } }); } catch (ExecutionException e) { log.error("Exception while accessing the P4InfoBrowser cache", e); return null; } }
Example #8
Source File: FabricPipeconfLoader.java From onos with Apache License 2.0 | 6 votes |
private PiPipeconf bmv2Pipeconf(String profile, String platform) throws FileNotFoundException { final URL bmv2JsonUrl = this.getClass().getResource(format( P4C_RES_BASE_PATH + BMV2_JSON, profile, BMV2, platform)); final URL p4InfoUrl = this.getClass().getResource(format( P4C_RES_BASE_PATH + P4INFO_TXT, profile, BMV2, platform)); final URL cpuPortUrl = this.getClass().getResource(format( P4C_RES_BASE_PATH + CPU_PORT_TXT, profile, BMV2, platform)); checkFileExists(bmv2JsonUrl, BMV2_JSON); checkFileExists(p4InfoUrl, P4INFO_TXT); checkFileExists(cpuPortUrl, CPU_PORT_TXT); final DefaultPiPipeconf.Builder builder = DefaultPiPipeconf.builder() .withId(makePipeconfId(platform, profile)) .addBehaviour(PortStatisticsDiscovery.class, FabricPortStatisticsDiscovery.class) .addExtension(PiPipeconf.ExtensionType.BMV2_JSON, bmv2JsonUrl); return build(builder, profile, p4InfoUrl, cpuPortUrl); }
Example #9
Source File: AbstractCodec.java From onos with Apache License 2.0 | 6 votes |
/** * Decodes the given collection of protobuf messages. Throws an exception if * one or more of the given protobuf messages cannot be decoded. The * returned list is guaranteed to have same size and order as the given * one. * * @param messages list of protobuf messages * @param metadata metadata * @param pipeconf pipeconf * @return list of objects * @throws CodecException if one or more of the given protobuf messages * cannot be decoded */ List<P> decodeAll(Collection<M> messages, X metadata, PiPipeconf pipeconf) throws CodecException { checkNotNull(messages); if (messages.isEmpty()) { return ImmutableList.of(); } final List<P> objects = decodeAllSkipException(messages, metadata, pipeconf); if (messages.size() != objects.size()) { throw new CodecException(format( "Unable to decode %d messages of %d given " + "(see previous logs for details)", messages.size() - objects.size(), messages.size())); } return objects; }
Example #10
Source File: PipeconfLoader.java From onos with Apache License 2.0 | 6 votes |
private static PiPipeconf buildBasicPipeconf() { final URL jsonUrl = PipeconfLoader.class.getResource(BASIC_JSON_PATH); final URL p4InfoUrl = PipeconfLoader.class.getResource(BASIC_P4INFO); return DefaultPiPipeconf.builder() .withId(BASIC_PIPECONF_ID) .withPipelineModel(parseP4Info(p4InfoUrl)) .addBehaviour(PiPipelineInterpreter.class, BasicInterpreterImpl.class) .addBehaviour(Pipeliner.class, BasicPipelinerImpl.class) .addBehaviour(PortStatisticsDiscovery.class, PortStatisticsDiscoveryImpl.class) .addExtension(P4_INFO_TEXT, p4InfoUrl) .addExtension(BMV2_JSON, jsonUrl) // Put here other target-specific extensions, // e.g. Tofino's bin and context.json. .build(); }
Example #11
Source File: MeterEntryCodec.java From onos with Apache License 2.0 | 6 votes |
@Override protected PiMeterCellConfig decode( P4RuntimeOuterClass.MeterEntry message, Object ignored, PiPipeconf pipeconf, P4InfoBrowser browser) throws P4InfoBrowser.NotFoundException { final String meterName = browser.meters() .getById(message.getMeterId()) .getPreamble() .getName(); return PiMeterCellConfig.builder() .withMeterCellId(PiMeterCellId.ofIndirect( PiMeterId.of(meterName), message.getIndex().getIndex())) .withMeterBand(new PiMeterBand(message.getConfig().getCir(), message.getConfig().getCburst())) .withMeterBand(new PiMeterBand(message.getConfig().getPir(), message.getConfig().getPburst())) .build(); }
Example #12
Source File: TableEntryCodec.java From onos with Apache License 2.0 | 6 votes |
@SuppressWarnings("OptionalUsedAsFieldOrParameterType") private P4RuntimeOuterClass.TableEntry.Builder keyMsgBuilder( PiTableId tableId, PiMatchKey matchKey, OptionalInt priority, PiPipeconf pipeconf, P4InfoBrowser browser) throws P4InfoBrowser.NotFoundException, CodecException { final P4RuntimeOuterClass.TableEntry.Builder tableEntryMsgBuilder = P4RuntimeOuterClass.TableEntry.newBuilder(); final P4InfoOuterClass.Preamble tablePreamble = browser.tables() .getByName(tableId.id()).getPreamble(); // Table id. tableEntryMsgBuilder.setTableId(tablePreamble.getId()); // Field matches. if (matchKey.equals(PiMatchKey.EMPTY)) { tableEntryMsgBuilder.setIsDefaultAction(true); } else { tableEntryMsgBuilder.addAllMatch( CODECS.fieldMatch().encodeAll( matchKey.fieldMatches(), tablePreamble, pipeconf)); } // Priority. priority.ifPresent(tableEntryMsgBuilder::setPriority); return tableEntryMsgBuilder; }
Example #13
Source File: PacketMetadataCodec.java From onos with Apache License 2.0 | 6 votes |
@Override protected PiPacketMetadata decode( P4RuntimeOuterClass.PacketMetadata message, P4InfoOuterClass.Preamble ctrlPktMetaPreamble, PiPipeconf pipeconf, P4InfoBrowser browser) throws P4InfoBrowser.NotFoundException { final String packetMetadataName = browser .packetMetadatas(ctrlPktMetaPreamble.getId()) .getById(message.getMetadataId()).getName(); final PiPacketMetadataId metadataId = PiPacketMetadataId .of(packetMetadataName); return PiPacketMetadata.builder() .withId(metadataId) .withValue(copyFrom(message.getValue().asReadOnlyByteBuffer())) .build(); }
Example #14
Source File: PiUtils.java From onos with Apache License 2.0 | 6 votes |
static PiPipelineInterpreter getInterpreterOrNull(Device device, PiPipeconf pipeconf) { if (device != null) { return device.is(PiPipelineInterpreter.class) ? device.as(PiPipelineInterpreter.class) : null; } else { // The case of device == null should be admitted only during unit testing. // In any other case, the interpreter should be constructed using the device.as() method to make sure that // behaviour's handler/data attributes are correctly populated. // FIXME: modify test class PiFlowRuleTranslatorTest to avoid passing null device // I.e. we need to create a device object that supports is/as method for obtaining the interpreter. log.warn("getInterpreterOrNull() called with device == null, is this a unit test?"); try { return (PiPipelineInterpreter) pipeconf.implementation(PiPipelineInterpreter.class) .orElse(null) .newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new IllegalArgumentException(format("Unable to instantiate interpreter of pipeconf %s", pipeconf.id())); } } }
Example #15
Source File: StreamClientImpl.java From onos with Apache License 2.0 | 6 votes |
private void handlePacketIn(P4RuntimeOuterClass.PacketIn packetInMsg) { if (log.isTraceEnabled()) { log.trace("Received packet-in from {}: {}", deviceId, packetInMsg); } if (!pipeconfService.getPipeconf(deviceId).isPresent()) { log.warn("Unable to handle packet-in from {}, missing pipeconf: {}", deviceId, TextFormat.shortDebugString(packetInMsg)); return; } // Decode packet message and post event. // TODO: consider implementing a cache to speed up // encoding/deconding of packet-in/out (e.g. LLDP, ARP) final PiPipeconf pipeconf = pipeconfService.getPipeconf(deviceId).get(); final PiPacketOperation pktOperation; try { pktOperation = CODECS.packetIn().decode( packetInMsg, null, pipeconf); } catch (CodecException e) { log.warn("Unable to process packet-int: {}", e.getMessage()); return; } controller.postEvent(new P4RuntimeEvent( P4RuntimeEvent.Type.PACKET_IN, new PacketInEvent(deviceId, pktOperation))); }
Example #16
Source File: PipelineConfigClientImpl.java From onos with Apache License 2.0 | 6 votes |
private boolean comparePipelineConfig( PiPipeconf pipeconf, ForwardingPipelineConfig cfgFromDevice) { if (cfgFromDevice == null) { return false; } final ForwardingPipelineConfig expectedCfg = buildForwardingPipelineConfigMsg( pipeconf, null); if (expectedCfg == null) { return false; } if (cfgFromDevice.hasCookie()) { return cfgFromDevice.getCookie().getCookie() == pipeconf.fingerprint(); } // No cookie. log.warn("{} returned GetForwardingPipelineConfigResponse " + "with 'cookie' field unset. " + "Will try by comparing 'p4_info'...", client.deviceId()); return cfgFromDevice.hasP4Info() && expectedCfg.hasP4Info() && cfgFromDevice.getP4Info().equals(expectedCfg.getP4Info()); }
Example #17
Source File: CounterEntryCodec.java From onos with Apache License 2.0 | 5 votes |
@Override protected P4RuntimeOuterClass.CounterEntry encodeKey( PiCounterCell piEntity, Object metadata, PiPipeconf pipeconf, P4InfoBrowser browser) throws P4InfoBrowser.NotFoundException { return keyMsgBuilder(piEntity.cellId(), browser).build(); }
Example #18
Source File: CounterEntryCodec.java From onos with Apache License 2.0 | 5 votes |
@Override protected PiCounterCell decode( P4RuntimeOuterClass.CounterEntry message, Object ignored, PiPipeconf pipeconf, P4InfoBrowser browser) throws P4InfoBrowser.NotFoundException { final String counterName = browser.counters() .getById(message.getCounterId()) .getPreamble() .getName(); return new PiCounterCell( PiCounterCellId.ofIndirect( PiCounterId.of(counterName), message.getIndex().getIndex()), message.getData().getPacketCount(), message.getData().getByteCount()); }
Example #19
Source File: PacketMetadataCodec.java From onos with Apache License 2.0 | 5 votes |
@Override protected P4RuntimeOuterClass.PacketMetadata encode( PiPacketMetadata piEntity, P4InfoOuterClass.Preamble ctrlPktMetaPreamble, PiPipeconf pipeconf, P4InfoBrowser browser) throws P4InfoBrowser.NotFoundException { final int metadataId = browser .packetMetadatas(ctrlPktMetaPreamble.getId()) .getByName(piEntity.id().id()).getId(); return P4RuntimeOuterClass.PacketMetadata.newBuilder() .setMetadataId(metadataId) .setValue(ByteString.copyFrom(piEntity.value().asReadOnlyBuffer())) .build(); }
Example #20
Source File: DirectMeterEntryCodec.java From onos with Apache License 2.0 | 5 votes |
private P4RuntimeOuterClass.DirectMeterEntry.Builder keyMsgBuilder( PiMeterCellId cellId, PiPipeconf pipeconf) throws CodecException { return P4RuntimeOuterClass.DirectMeterEntry.newBuilder() .setTableEntry(CODECS.tableEntry().encodeKey( cellId.tableEntry(), null, pipeconf)); }
Example #21
Source File: PiPipeconfManager.java From onos with Apache License 2.0 | 5 votes |
@Override public void unregister(PiPipeconfId pipeconfId) throws IllegalStateException { checkNotNull(pipeconfId); // TODO add mechanism to remove from device. if (!pipeconfs.containsKey(pipeconfId)) { throw new IllegalStateException(format("Pipeconf %s is not registered", pipeconfId)); } // TODO remove the binding from the distributed Store when the lifecycle of a pipeconf is defined. // pipeconfMappingStore.removeBindings(pipeconfId); final PiPipeconf pipeconf = pipeconfs.remove(pipeconfId); log.info("Unregistered pipeconf: {} (fingerprint={})", pipeconfId, HexString.toHexString(pipeconf.fingerprint())); post(new PiPipeconfEvent(PiPipeconfEvent.Type.UNREGISTERED, pipeconfId)); }
Example #22
Source File: WriteRequestImpl.java From onos with Apache License 2.0 | 5 votes |
WriteRequestImpl(P4RuntimeClientImpl client, long p4DeviceId, PiPipeconf pipeconf) { this.client = checkNotNull(client); this.pipeconf = checkNotNull(pipeconf); this.requestMsg = P4RuntimeOuterClass.WriteRequest.newBuilder() .setDeviceId(p4DeviceId); this.responseBuilder = WriteResponseImpl.builder(client.deviceId()); }
Example #23
Source File: ActionProfileGroupCodec.java From onos with Apache License 2.0 | 5 votes |
@Override protected ActionProfileGroup encodeKey( PiActionProfileGroupHandle handle, Object ignored, PiPipeconf pipeconf, P4InfoBrowser browser) throws P4InfoBrowser.NotFoundException { return keyMsgBuilder(handle.actionProfile(), handle.groupId(), browser) .build(); }
Example #24
Source File: CloneSessionEntryCodec.java From onos with Apache License 2.0 | 5 votes |
@Override protected P4RuntimeOuterClass.CloneSessionEntry encodeKey( PiCloneSessionEntry piEntity, Object metadata, PiPipeconf pipeconf, P4InfoBrowser browser) { return P4RuntimeOuterClass.CloneSessionEntry.newBuilder() .setSessionId(piEntity.sessionId()).build(); }
Example #25
Source File: ActionProfileMemberCodec.java From onos with Apache License 2.0 | 5 votes |
@Override protected ActionProfileMember encodeKey( PiActionProfileMember piEntity, Object metadata, PiPipeconf pipeconf, P4InfoBrowser browser) throws P4InfoBrowser.NotFoundException { return keyMsgBuilder( piEntity.actionProfile(), piEntity.id(), browser) .build(); }
Example #26
Source File: PiReplicationGroupTranslatorImpl.java From onos with Apache License 2.0 | 5 votes |
/** * Returns a PI PRE entry equivalent to the given group, for the given * pipeconf and device. * <p> * The passed group is expected to have type {@link GroupDescription.Type#ALL} * or {@link GroupDescription.Type#CLONE}. * * @param group group * @param pipeconf pipeconf * @param device device * @return PI PRE entry * @throws PiTranslationException if the group cannot be translated */ static PiPreEntry translate(Group group, PiPipeconf pipeconf, Device device) throws PiTranslationException { checkNotNull(group); final List<Instruction> instructions = group.buckets().buckets().stream() .flatMap(b -> b.treatment().allInstructions().stream()) .collect(Collectors.toList()); final boolean hasNonOutputInstr = instructions.stream() .anyMatch(i -> !i.type().equals(Instruction.Type.OUTPUT)); if (instructions.size() != group.buckets().buckets().size() || hasNonOutputInstr) { throw new PiTranslationException( "support only groups with just one OUTPUT instruction per bucket"); } final List<OutputInstruction> outInstructions = instructions.stream() .map(i -> (OutputInstruction) i) .collect(Collectors.toList()); switch (group.type()) { case ALL: return PiMulticastGroupEntry.builder() .withGroupId(group.id().id()) .addReplicas(getReplicas(outInstructions, device)) .build(); case CLONE: return PiCloneSessionEntry.builder() .withSessionId(group.id().id()) .addReplicas(getReplicas(outInstructions, device)) .build(); default: throw new PiTranslationException(format( "group type %s not supported", group.type())); } }
Example #27
Source File: ActionProfileMemberCodec.java From onos with Apache License 2.0 | 5 votes |
@Override public ActionProfileMember encode( PiActionProfileMember piEntity, Object ignored, PiPipeconf pipeconf, P4InfoBrowser browser) throws CodecException, P4InfoBrowser.NotFoundException { return keyMsgBuilder( piEntity.actionProfile(), piEntity.id(), browser) .setAction(CODECS.action().encode( piEntity.action(), null, pipeconf)) .build(); }
Example #28
Source File: PiTranslationServiceImpl.java From onos with Apache License 2.0 | 5 votes |
@Override public PiMeterCellConfig translate(Meter original, PiPipeconf pipeconf) throws PiTranslationException { checkNotNull(original); checkNotNull(pipeconf); return PiMeterTranslatorImpl .translate(original, pipeconf, getDevice(original.deviceId())); }
Example #29
Source File: AbstractCodec.java From onos with Apache License 2.0 | 5 votes |
/** * Returns a P4Info browser for the given pipeconf or throws a * CodecException if not possible. * * @param pipeconf pipeconf * @return P4Info browser * @throws CodecException if a P4Info browser cannot be obtained */ P4InfoBrowser browserOrFail(PiPipeconf pipeconf) throws CodecException { checkNotNull(pipeconf); final P4InfoBrowser browser = PipeconfHelper.getP4InfoBrowser(pipeconf); if (browser == null) { throw new CodecException(format( "Unable to get P4InfoBrowser for pipeconf %s", pipeconf.id())); } return browser; }
Example #30
Source File: PipeconfFactory.java From onos with Apache License 2.0 | 5 votes |
private PiPipeconf buildPipeconf() throws P4InfoParserException { final PiPipelineModel pipelineModel = P4InfoParser.parse(P4INFO_URL); return DefaultPiPipeconf.builder() .withId(PIPECONF_ID) .withPipelineModel(pipelineModel) .addBehaviour(PiPipelineInterpreter.class, PipelineInterpreterImpl.class) .addBehaviour(PortStatisticsDiscovery.class, PortStatisticsDiscoveryImpl.class) // Since mytunnel.p4 defines only 1 table, we re-use the existing single-table pipeliner. .addBehaviour(Pipeliner.class, DefaultSingleTablePipeline.class) .addExtension(P4_INFO_TEXT, P4INFO_URL) .addExtension(BMV2_JSON, BMV2_JSON_URL) .build(); }