IPAddressString ipAddrString = new IPAddressString("fe80::8b2:d61e:e5c:b333%15"); IPAddress addr = ipAddrString.getAddress(); if(addr.isIPv6()) { IPv6Address ipv6Addr = addr.toIPv6(); String zone = ipv6Addr.getZone(); IPv6Address noZoneAddr = new IPv6Address(ipv6Addr.getBytes()); System.out.println(zone); System.out.println(noZoneAddr); }
private OFPort buildPort(PortNumber port) { return OFPort.of((int) port.toLong()); }
private TableStatisticsEntry buildTableStatistics(DeviceId deviceId, OFTableStatsEntry ofEntry) { TableStatisticsEntry entry = null; if (ofEntry != null) { entry = new DefaultTableStatisticsEntry(deviceId, ofEntry.getTableId().getValue(), ofEntry.getActiveCount(), ofEntry.getLookupCount().getValue(), ofEntry.getMatchedCount().getValue()); } return entry; } }
/** * Build a portDescription from a given Ethernet port description. * * @param port the port to build from. * @return portDescription for the port. */ private PortDescription buildPortDescription(OFPortDesc port) { PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); boolean enabled = !port.getState().contains(OFPortState.LINK_DOWN) && !port.getConfig().contains(OFPortConfig.PORT_DOWN); Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString()); return new DefaultPortDescription(portNo, enabled, type, portSpeed(port), annotations); }
private OFAction buildL2Modification(Instruction i) { L2ModificationInstruction l2m = (L2ModificationInstruction) i; ModEtherInstruction eth; switch (l2m.subtype()) { case ETH_DST: eth = (ModEtherInstruction) l2m; return factory().actions().setDlDst(MacAddress.of(eth.mac().toLong())); case ETH_SRC: eth = (ModEtherInstruction) l2m; return factory().actions().setDlSrc(MacAddress.of(eth.mac().toLong())); case VLAN_ID: ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m; return factory().actions().setVlanVid(VlanVid.ofVlan(vlanId.vlanId().toShort())); case VLAN_PCP: ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m; return factory().actions().setVlanPcp(VlanPcp.of(vlanPcp.vlanPcp())); case VLAN_POP: return factory().actions().stripVlan(); case VLAN_PUSH: return null; default: log.warn("Unimplemented action type {}.", l2m.subtype()); break; } return null; }
@Override public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) { ExtensionSelectorType type = extensionSelector.type(); if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SPI.type())) { NiciraMatchNshSpi niciraNshSpi = (NiciraMatchNshSpi) extensionSelector; return factory.oxms().nsp(U32.of(niciraNshSpi.nshSpi().servicePathId())); } if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_SI.type())) { NiciraMatchNshSi niciraNshSi = (NiciraMatchNshSi) extensionSelector; return factory.oxms().nsi(U8.of(niciraNshSi.nshSi().serviceIndex())); } if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_ENCAP_ETH_TYPE.type())) { NiciraMatchEncapEthType niciraEncapEthType = (NiciraMatchEncapEthType) extensionSelector; return factory.oxms().encapEthType(U16.of(niciraEncapEthType.encapEthType())); } if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH1.type())) { // TODO } if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH2.type())) { // TODO } if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH3.type())) { // TODO } if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.NICIRA_MATCH_NSH_CH4.type())) { // TODO } return null; }
@Override public OFOxm<?> mapSelector(OFFactory factory, ExtensionSelector extensionSelector) { ExtensionSelectorType type = extensionSelector.type(); if (type.equals(ExtensionSelectorType.ExtensionSelectorTypes.OFDPA_MATCH_VLAN_VID.type())) { VlanId vlanId = ((OfdpaMatchVlanVid) extensionSelector).vlanId(); // Special VLAN 0x0000/0x1FFF required by OFDPA if (vlanId.equals(VlanId.NONE)) { OFVlanVidMatch vid = OFVlanVidMatch.ofRawVid((short) 0x0000); OFVlanVidMatch mask = OFVlanVidMatch.ofRawVid((short) 0x1FFF); return factory.oxms().vlanVidMasked(vid, mask); // Normal case } else if (vlanId.equals(VlanId.ANY)) { return factory.oxms().vlanVidMasked(OFVlanVidMatch.PRESENT, OFVlanVidMatch.PRESENT); } else { return factory.oxms().vlanVid(OFVlanVidMatch.ofVlanVid(VlanVid.ofVlan(vlanId.toShort()))); } } throw new UnsupportedOperationException( "Unexpected ExtensionSelector: " + extensionSelector.toString()); }
@Override public Integer inPort() { checkPermission(PACKET_READ); return pktinInPort().getPortNumber(); }
@Override public Optional<Long> cookie() { checkPermission(PACKET_READ); if (pktin.getVersion() != OFVersion.OF_10) { return Optional.of(pktin.getCookie().getValue()); } else { return Optional.empty(); } }
@Override public ExtensionSelector mapOxm(OFOxm<?> oxm) { if (oxm.getMatchField() == MatchField.NSP) { OFOxmNsp oxmField = (OFOxmNsp) oxm; return new NiciraMatchNshSpi(NshServicePathId.of(oxmField.getValue().getRaw())); } if (oxm.getMatchField() == MatchField.NSI) { OFOxmNsi oxmField = (OFOxmNsi) oxm; return new NiciraMatchNshSi(NshServiceIndex.of(oxmField.getValue().getRaw())); } if (oxm.getMatchField() == MatchField.ENCAP_ETH_TYPE) { OFOxmEncapEthType oxmField = (OFOxmEncapEthType) oxm; return new NiciraMatchEncapEthType(oxmField.getValue().getRaw()); } return null; }
@Override public OFFlowMod buildFlowDel() { Match match = buildMatch(); long cookie = flowRule().id().value(); OFFlowDeleteStrict fm = factory().buildFlowDeleteStrict() .setXid(xid) .setCookie(U64.of(cookie)) .setBufferId(OFBufferId.NO_BUFFER) .setMatch(match) .setFlags(Collections.singleton(OFFlowModFlags.SEND_FLOW_REM)) .setPriority(flowRule().priority()) .setTableId(TableId.of(flowRule().tableId())) .build(); return fm; }
private long portSpeed(OFPortDesc port) { if (port.getVersion() == OFVersion.OF_13) { // Note: getCurrSpeed() returns a value in kbps (this also applies to OF_11 and OF_12) return port.getCurrSpeed() / KBPS; } PortSpeed portSpeed = PortSpeed.SPEED_NONE; for (OFPortFeatures feat : port.getCurr()) { portSpeed = PortSpeed.max(portSpeed, feat.getPortSpeed()); } return portSpeed.getSpeedBps() / MBPS; }
/** * Builds the GroupDel OF message. * * @return GroupDel OF message */ public OFGroupDelete buildGroupDel() { OFGroupDelete groupMsg = factory.buildGroupDelete() .setGroup(OFGroup.of(groupId.id())) .setGroupType(OFGroupType.SELECT) .setXid(xid) .build(); return groupMsg; }
@Override void processOFFeaturesReply(OFChannelHandler h, OFFeaturesReply m) throws IOException { h.thisdpid = m.getDatapathId().getLong(); log.debug("Received features reply for switch at {} with dpid {}", h.getSwitchInfoString(), h.thisdpid); h.featuresReply = m; //temp store if (h.ofVersion == OFVersion.OF_10) { h.sendHandshakeSetConfig(); h.setState(WAIT_CONFIG_REPLY); } else { //version is 1.3, must get switchport information h.sendHandshakeOFPortDescRequest(); h.setState(WAIT_PORT_DESC_REPLY); } } @Override
private OFInstruction buildTableGoto(Instructions.TableTypeTransition i) { OFInstruction instruction = factory().instructions().gotoTable( TableId.of(i.tableId())); return instruction; }
private OFPortDesc portDesc(PortNumber port) { OFPortDesc.Builder builder = OFFactoryVer10.INSTANCE.buildPortDesc(); builder.setPortNo(OFPort.of((int) port.toLong())); return builder.build(); }
private PortDescription buildPortDescription(OFPortStatus status) { OFPortDesc port = status.getDesc(); if (status.getReason() != OFPortReason.DELETE) { return buildPortDescription(port); } else { PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); Port.Type type = port.getCurr().contains(OFPortFeatures.PF_FIBER) ? FIBER : COPPER; SparseAnnotations annotations = makePortAnnotation(port.getName(), port.getHwAddr().toString()); return new DefaultPortDescription(portNo, false, type, portSpeed(port), annotations); } }
private OFActionOutput buildOutput(Integer port) { OFActionOutput act = sw.factory().actions() .buildOutput() .setPort(OFPort.of(port)) .build(); return act; }
/** * Build a portDescription from a given port description describing a fiber switch optical port. * * @param port description property type. * @param port the port to build from. * @return portDescription for the port. */ private PortDescription buildPortDescription(OFCalientPortDescStatsEntry port) { PortNumber portNo = PortNumber.portNumber(port.getPortNo().getPortNumber()); // Use the alias name if it's available String name = port.getName(); List<OFCalientPortDescProp> props = port.getProperties(); if (props != null && props.size() > 0) { OFCalientPortDescPropOptical propOptical = (OFCalientPortDescPropOptical) props.get(0); if (propOptical != null) { name = propOptical.getInAlias(); } } // FIXME when Calient OF agent reports port status boolean enabled = true; SparseAnnotations annotations = makePortAnnotation(name, port.getHwAddr().toString()); // S160 data sheet // Wavelength range: 1260 - 1630 nm, grid is irrelevant for this type of switch return omsPortDescription(portNo, enabled, Spectrum.U_BAND_MIN, Spectrum.O_BAND_MAX, Frequency.ofGHz(100), annotations); }