protected void writeMacAddress(final MacAddress address, final ByteBuf outBuffer) { outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(address)); // 48 b + mask [OF 1.3.2 spec] } }
/** * Converts binary data into mac address * @param input input ByteBuf * @return mac address */ public static MacAddress convertMacAddress(final ByteBuf input) { byte[] address = new byte[EncodeConstants.MAC_ADDRESS_LENGTH]; input.readBytes(address); return IetfYangUtil.INSTANCE.macAddressFor(address); } }
@Override public void serializeExtendedCommunity(final ExtendedCommunity extendedCommunity, final ByteBuf byteAggregator) { Preconditions.checkArgument(extendedCommunity instanceof EsImportRouteExtendedCommunityCase, "The extended community %s is not EsImportRouteExtendedCommunityCaseCase type.", extendedCommunity); final EsImportRouteExtendedCommunity extCom = ((EsImportRouteExtendedCommunityCase) extendedCommunity).getEsImportRouteExtendedCommunity(); byteAggregator.writeBytes(IetfYangUtil.INSTANCE.bytesFor(extCom.getEsImport())); }
@Override public Esi parseEsi(final ByteBuf buffer) { final MacAutoGenerated t3 = new MacAutoGeneratedBuilder() .setSystemMacAddress(IetfYangUtil.INSTANCE.macAddressFor(ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH))) .setLocalDiscriminator(new Uint24(Long.valueOf(buffer.readUnsignedMedium()))).build(); return new MacAutoGeneratedCaseBuilder().setMacAutoGenerated(t3).build(); } }
@Override public void serializeBody(final Esi esi, final ByteBuf body) { Preconditions.checkArgument(esi instanceof MacAutoGeneratedCase, "Unknown esi instance. Passed %s. Needed MacAutoGeneratedCase.", esi.getClass()); final MacAutoGenerated macAuto = ((MacAutoGeneratedCase) esi).getMacAutoGenerated(); body.writeBytes(IetfYangUtil.INSTANCE.bytesFor(macAuto.getSystemMacAddress())); ByteBufWriteUtil.writeMedium(macAuto.getLocalDiscriminator().getValue().intValue(), body); }
@Override public ExtendedCommunity parseExtendedCommunity(final ByteBuf buffer) throws BGPDocumentedException, BGPParsingException { final MacAddress mac = IetfYangUtil.INSTANCE.macAddressFor(ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH)); return new EsImportRouteExtendedCommunityCaseBuilder().setEsImportRouteExtendedCommunity( new EsImportRouteExtendedCommunityBuilder().setEsImport(mac).build()).build(); }
@Override public void serializeBody(final Esi esi, final ByteBuf body) { Preconditions.checkArgument(esi instanceof LacpAutoGeneratedCase, "Unknown esi instance. Passed %s. Needed LacpAutoGeneratedCase.", esi.getClass()); final LacpAutoGenerated lacp = ((LacpAutoGeneratedCase) esi).getLacpAutoGenerated(); body.writeBytes(IetfYangUtil.INSTANCE.bytesFor(lacp.getCeLacpMacAddress())); ByteBufWriteUtil.writeUnsignedShort(lacp.getCeLacpPortKey(), body); body.writeZero(ZERO_BYTE); }
@Override public Esi parseEsi(final ByteBuf buffer) { final LanAutoGenerated t2 = new LanAutoGeneratedBuilder() .setRootBridgeMacAddress(IetfYangUtil.INSTANCE.macAddressFor(ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH))) .setRootBridgePriority(buffer.readUnsignedShort()).build(); return new LanAutoGeneratedCaseBuilder().setLanAutoGenerated(t2).build(); } }
@Override public void serializeBody(final Esi esi, final ByteBuf body) { Preconditions.checkArgument(esi instanceof LanAutoGeneratedCase, "Unknown esi instance. Passed %s. Needed LanAutoGeneratedCase.", esi.getClass()); final LanAutoGenerated lan = ((LanAutoGeneratedCase) esi).getLanAutoGenerated(); body.writeBytes(IetfYangUtil.INSTANCE.bytesFor(lan.getRootBridgeMacAddress())); ByteBufWriteUtil.writeUnsignedShort(lan.getRootBridgePriority(), body); body.writeZero(ZERO_BYTE); }
@Override public Esi parseEsi(final ByteBuf buffer) { final LacpAutoGenerated t1 = new LacpAutoGeneratedBuilder() .setCeLacpMacAddress(IetfYangUtil.INSTANCE.macAddressFor(ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH))) .setCeLacpPortKey(buffer.readUnsignedShort()) .build(); return new LacpAutoGeneratedCaseBuilder().setLacpAutoGenerated(t1).build(); } }
@Override public void serialize(final Action action, final ByteBuf outBuffer) { super.serialize(action, outBuffer); outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(((SetDlSrcCase) action.getActionChoice()) .getSetDlSrcAction().getDlSrcAddress())); outBuffer.writeZero(ActionConstants.PADDING_IN_DL_ADDRESS_ACTION); }
@Override public EvpnChoice parseEvpn(final ByteBuf buffer) { final Esi esi = SimpleEsiTypeRegistry.getInstance().parseEsi(buffer.readSlice(ESI_SIZE)); final EthernetTagId eti = new EthernetTagIdBuilder().setVlanId(buffer.readUnsignedInt()).build(); buffer.skipBytes(1); final MacAddress mac = IetfYangUtil.INSTANCE.macAddressFor(ByteArray.readBytes(buffer, MAC_ADDRESS_LENGTH)); final IpAddress ip = parseIp(buffer); final MplsLabel label1 = mplsLabelForByteBuf(buffer); MplsLabel label2; if (buffer.readableBytes() > 0) { label2 = mplsLabelForByteBuf(buffer); } else { label2 = null; } final MacIpAdvRouteBuilder builder = new MacIpAdvRouteBuilder().setEsi(esi).setEthernetTagId(eti).setMacAddress(mac).setIpAddress(ip) .setMplsLabel1(label1).setMplsLabel2(label2); return new MacIpAdvRouteCaseBuilder().setMacIpAdvRoute(builder.build()).build(); }
@Override public void serialize(final Action action, final ByteBuf outBuffer) { super.serialize(action, outBuffer); outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(((SetDlDstCase) action.getActionChoice()) .getSetDlDstAction().getDlDstAddress())); outBuffer.writeZero(ActionConstants.PADDING_IN_DL_ADDRESS_ACTION); }
@Override public void serialize(final PortModInput message, final ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeShort(message.getPortNo().getValue().intValue()); outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(message.getHwAddress())); outBuffer.writeInt(createPortConfigBitmask(message.getConfigV10())); outBuffer.writeInt(createPortConfigBitmask(message.getMaskV10())); outBuffer.writeInt(createPortFeaturesBitmask(message.getAdvertiseV10())); outBuffer.writeZero(PADDING_IN_PORT_MOD_MESSAGE); ByteBufUtils.updateOFHeaderLength(outBuffer); }
@Override public void serialize(final PortModInput message, final ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeInt(message.getPortNo().getValue().intValue()); outBuffer.writeZero(PADDING_IN_PORT_MOD_MESSAGE_01); outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(message.getHwAddress())); outBuffer.writeZero(PADDING_IN_PORT_MOD_MESSAGE_02); outBuffer.writeInt(createPortConfigBitmask(message.getConfig())); outBuffer.writeInt(createPortConfigBitmask(message.getMask())); outBuffer.writeInt(createPortFeaturesBitmask(message.getAdvertise())); outBuffer.writeZero(PADDING_IN_PORT_MOD_MESSAGE_03); ByteBufUtils.updateOFHeaderLength(outBuffer); }
/** * Serializes ofp_match (OpenFlow v1.0) * @param outBuffer output ByteBuf * @param match match to be serialized */ @Override public void serialize(final MatchV10 match, final ByteBuf outBuffer) { outBuffer.writeInt(encodeWildcards(match.getWildcards(), match.getNwSrcMask(), match.getNwDstMask())); outBuffer.writeShort(match.getInPort()); outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(match.getDlSrc())); outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(match.getDlDst())); outBuffer.writeShort(match.getDlVlan()); outBuffer.writeByte(match.getDlVlanPcp()); outBuffer.writeZero(PADDING_IN_MATCH); outBuffer.writeShort(match.getDlType()); outBuffer.writeByte(match.getNwTos()); outBuffer.writeByte(match.getNwProto()); outBuffer.writeZero(PADDING_IN_MATCH_2); outBuffer.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressBytes(match.getNwSrc())); outBuffer.writeBytes(IetfInetUtil.INSTANCE.ipv4AddressBytes(match.getNwDst())); outBuffer.writeShort(match.getTpSrc()); outBuffer.writeShort(match.getTpDst()); }
private static ByteBuf serializeBody(final MacIpAdvRouteCase evpnCase) { final ByteBuf body = Unpooled.buffer(); final MacIpAdvRoute evpn = evpnCase.getMacIpAdvRoute(); final Esi esi = evpn.getEsi(); if (esi != null) { SimpleEsiTypeRegistry.getInstance().serializeEsi(evpn.getEsi(), body); } ByteBufWriteUtil.writeUnsignedInt(evpn.getEthernetTagId().getVlanId(), body); final MacAddress mac = evpn.getMacAddress(); body.writeByte(MAC_ADDRESS_LENGTH * BITS_SIZE); body.writeBytes(IetfYangUtil.INSTANCE.bytesFor(mac)); final ByteBuf ipAddress = serializeIp(evpn.getIpAddress()); Preconditions.checkArgument(ipAddress.readableBytes() > 0); body.writeBytes(ipAddress); final MplsLabel mpls1 = evpn.getMplsLabel1(); if (mpls1 != null) { body.writeBytes(byteBufForMplsLabel(mpls1)); } final MplsLabel mpls2 = evpn.getMplsLabel2(); if (mpls2 != null) { body.writeBytes(byteBufForMplsLabel(mpls2)); } return body; }
@Override public void serialize(final GetFeaturesOutput message, final ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeLong(message.getDatapathId().longValue()); outBuffer.writeInt(message.getBuffers().intValue()); outBuffer.writeByte(message.getTables().intValue()); outBuffer.writeZero(PADDING); outBuffer.writeInt(createCapabilities(message.getCapabilitiesV10())); outBuffer.writeInt(createActionsV10(message.getActionsV10())); for (PhyPort port : message.getPhyPort()) { outBuffer.writeShort(port.getPortNo().intValue()); outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(port.getHwAddr())); writeName(port.getName(), outBuffer); writePortConfig(port.getConfigV10(), outBuffer); writePortState(port.getStateV10(), outBuffer); writePortFeature(port.getCurrentFeaturesV10(), outBuffer); writePortFeature(port.getAdvertisedFeaturesV10(), outBuffer); writePortFeature(port.getSupportedFeaturesV10(), outBuffer); writePortFeature(port.getPeerFeaturesV10(), outBuffer); } ByteBufUtils.updateOFHeaderLength(outBuffer); }
private void serializePortDescBody(final MultipartReplyBody body, final ByteBuf outBuffer) { MultipartReplyPortDescCase portCase = (MultipartReplyPortDescCase) body; MultipartReplyPortDesc portDesc = portCase.getMultipartReplyPortDesc(); for (Ports port : portDesc.getPorts()) { outBuffer.writeInt(port.getPortNo().intValue()); // Assuming PortNo // = PortId outBuffer.writeZero(PORT_DESC_PADDING_1); outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(port.getHwAddr())); outBuffer.writeZero(PORT_DESC_PADDING_2); writeName(port.getName(), outBuffer); writePortConfig(port.getConfig(), outBuffer); writePortState(port.getState(), outBuffer); writePortFeatures(port.getCurrentFeatures(), outBuffer); writePortFeatures(port.getAdvertisedFeatures(), outBuffer); writePortFeatures(port.getSupportedFeatures(), outBuffer); writePortFeatures(port.getPeerFeatures(), outBuffer); outBuffer.writeInt(port.getCurrSpeed().intValue()); outBuffer.writeInt(port.getMaxSpeed().intValue()); } }
@Override public void serialize(final PortStatusMessage message, final ByteBuf outBuffer) { ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH); outBuffer.writeByte(message.getReason().getIntValue()); outBuffer.writeZero(PADDING); outBuffer.writeInt(message.getPortNo().intValue()); outBuffer.writeZero(PORT_PADDING_1); outBuffer.writeBytes(IetfYangUtil.INSTANCE.bytesFor(message.getHwAddr())); outBuffer.writeZero(PORT_PADDING_2); writeName(message.getName(), outBuffer); writePortConfig(message.getConfig(), outBuffer); writePortState(message.getState(), outBuffer); writePortFeatures(message.getCurrentFeatures(), outBuffer); writePortFeatures(message.getAdvertisedFeatures(), outBuffer); writePortFeatures(message.getSupportedFeatures(), outBuffer); writePortFeatures(message.getPeerFeatures(), outBuffer); outBuffer.writeInt(message.getCurrSpeed().intValue()); outBuffer.writeInt(message.getMaxSpeed().intValue()); ByteBufUtils.updateOFHeaderLength(outBuffer); }