public synchronized BigInteger getDatapathID(ConnectionAdapter connectionAdapter) throws NullPointerException { if (connectionAdapterMap.containsKey(connectionAdapter)) { GetFeaturesOutput obj = connectionAdapterMap.get(connectionAdapter); if (obj != null) { return obj.getDatapathId(); } } return null; }
public synchronized ConnectionAdapter getConnectionAdapter(Long datapathId) throws NullPointerException { for (ConnectionAdapter conn : connectionAdapterMap.keySet()) { if (connectionAdapterMap.get(conn).getDatapathId().longValue() == datapathId) { return conn; } } return null; }
/** * @param features switch feature output * @param seed seed value * @return connection cookie key * @see #createConnectionCookie(BigInteger,short, int) */ public static SwitchConnectionDistinguisher createConnectionCookie( GetFeaturesOutput features, int seed) { return createConnectionCookie(features.getDatapathId(), features.getAuxiliaryId(), seed); }
@Override public void serialize(GetFeaturesOutput message, 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.writeByte(message.getAuxiliaryId().intValue()); outBuffer.writeZero(PADDING); writeCapabilities(message.getCapabilities(), outBuffer); outBuffer.writeInt(message.getReserved().intValue()); ByteBufUtils.updateOFHeaderLength(outBuffer); }
public void sendGetFeaturesOuputToCore(final Short proposedVersion, final int moduleId, final ConnectionAdapter connectionAdapter) { GetFeaturesOutput featureOutput = getFeaturesFromRegistry(connectionAdapter); shimRelay.sendOpenFlowMessageToCore(ShimSwitchConnectionHandlerImpl.coreConnector, featureOutput, proposedVersion, featureOutput.getXid(), featureOutput.getDatapathId().shortValue(), moduleId); }
public void setSlaveRole(SessionContext sessionContext) { OfpRole newRole = OfpRole.BECOMESLAVE; if (sessionContext != null) { final BigInteger targetSwitchDPId = sessionContext.getFeatures().getDatapathId(); LOG.debug("setSlaveRole: Set controller as a SLAVE controller for {}", targetSwitchDPId.toString()); RolePushTask task = new RolePushTask(newRole, sessionContext); ListenableFuture<Boolean> rolePushResult = pool.submit(task); final CheckedFuture<Boolean, RolePushException> rolePushResultChecked = RoleUtil.makeCheckedRuleRequestFxResult(rolePushResult); Futures.addCallback(rolePushResult, new FutureCallback<Boolean>(){ @Override public void onSuccess(Boolean result){ LOG.debug("setSlaveRole: Controller is set as a SLAVE for {}", targetSwitchDPId.toString()); } @Override public void onFailure(Throwable e){ LOG.error("setSlaveRole: Role request to set controller as a SLAVE failed for {}", targetSwitchDPId.toString(), e); } }); } else { LOG.warn("setSlaveRole: sessionContext is not set. Device is not connected anymore"); } }
@Override public List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sc, OfHeader msg) { List<DataObject> results = null; if(msg instanceof NotificationQueueWrapper) { NotificationQueueWrapper wrappedNotification = (NotificationQueueWrapper) msg; BigInteger datapathId = sc.getFeatures().getDatapathId(); Short version = wrappedNotification.getVersion(); LOG.debug("NotificationQueueWrapper: version {} dataPathId {} notification {}", version, datapathId, wrappedNotification.getImplementedInterface()); results = Lists.newArrayList((DataObject) wrappedNotification.getNotification()); } else { // TODO - Do something smarter than returning null if translation fails... what Exception should we throw here? results = Collections.emptyList(); } return results; }
@Override public List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sc, OfHeader msg) { if(msg instanceof PortStatusMessage) { PortStatusMessage port = (PortStatusMessage)msg; List<DataObject> list = new CopyOnWriteArrayList<DataObject>(); BigInteger datapathId = sc.getFeatures().getDatapathId(); Long portNo = port.getPortNo(); Short version = port.getVersion(); if(port.getReason() == PortReason.OFPPRDELETE){ LOG.debug("PortStatusMessage: version {} dataPathId {} portNo {} reason {}",version, datapathId,portNo,port.getReason()); list.add(PortTranslatorUtil.translatePortRemoved(version, datapathId, portNo, port)); }else{ LOG.debug("PortStatusMessage: version {} dataPathId {} portNo {}",version, datapathId,portNo); list.add(PortTranslatorUtil.translatePort(version, datapathId, portNo, port)); } return list; } else { // TODO - Do something smarter than returning null if translation fails... what Exception should we throw here? return Collections.emptyList(); } } }
@Override public List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sc, OfHeader msg) { if (msg instanceof GetFeaturesOutput) { GetFeaturesOutput features = (GetFeaturesOutput) msg; List<DataObject> list = new CopyOnWriteArrayList<DataObject>(); BigInteger datapathId = sc.getFeatures().getDatapathId(); if( features.getPhyPort() != null ) { for (PhyPort port : features.getPhyPort()) { list.add(PortTranslatorUtil.translatePort(msg.getVersion(), datapathId, port.getPortNo(), port)); } } return list; } else { // TODO - Do something smarter than returning null if translation fails... what Exception should we throw here? return Collections.emptyList(); } } }
@Override public List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sc, OfHeader msg) { if(msg instanceof MultipartReply && ((MultipartReply) msg).getType() == MultipartType.OFPMPPORTDESC) { BigInteger datapathId = sc.getFeatures().getDatapathId(); LOG.trace("MultiPartReplyPortToNodeConnectorUpdatedTranslator Being translated to NodeConnectorUpdated "); MultipartReplyMessage message = (MultipartReplyMessage) msg; MultipartReplyPortDescCase caseBody = (MultipartReplyPortDescCase) message.getMultipartReplyBody(); MultipartReplyPortDesc body = caseBody.getMultipartReplyPortDesc(); List<DataObject> list = new CopyOnWriteArrayList<DataObject>(); for ( Ports port : body.getPorts() ) { LOG.debug("Port: " + port); list.add(PortTranslatorUtil.translatePort(msg.getVersion(), datapathId, port.getPortNo(), port)); } return list; } else { return Collections.emptyList(); } }
@Override public void onSuccess(RpcResult<GetFeaturesOutput> rpcFeatures) { LOG.trace("features are back"); if (rpcFeatures.isSuccessful()) { GetFeaturesOutput featureOutput = rpcFeatures.getResult(); LOG.debug("obtained features: datapathId={}", featureOutput.getDatapathId()); LOG.debug("obtained features: auxiliaryId={}", featureOutput.getAuxiliaryId()); LOG.trace("handshake SETTLED: version={}, datapathId={}, auxiliaryId={}", version, featureOutput.getDatapathId(), featureOutput.getAuxiliaryId()); handshakeListener.onHandshakeSuccessful(featureOutput, proposedVersion); } else { // handshake failed LOG.warn("issuing disconnect during handshake [{}]", connectionAdapter.getRemoteAddress()); for (RpcError rpcError : rpcFeatures.getErrors()) { LOG.debug("handshake - features failure [{}]: i:{} | m:{} | s:{}", xid, rpcError.getInfo(), rpcError.getMessage(), rpcError.getSeverity(), rpcError.getCause() ); } handshakeListener.onHandshakeFailure(); } LOG.debug("postHandshake DONE"); }
@Override public List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sc, OfHeader msg) { if (msg instanceof ErrorMessage) { ErrorMessage message = (ErrorMessage) msg; List<DataObject> list = new CopyOnWriteArrayList<DataObject>(); if (LOG.isDebugEnabled()) { String hexData = "n/a"; if (message.getData() != null) { hexData = ByteUtil.bytesToHexstring(message.getData(), " "); } LOG.debug(" Error Message received: type={}[{}], code={}[{}], data=[{}] ", message.getType(), message.getTypeString(), message.getCode(), message.getCodeString(), hexData); } // TODO -- Augmentation is not handled ErrorType type = decodeErrorType(message.getType()); NodeRef node = new NodeRef( InventoryDataServiceUtil.identifierFromDatapathId( sc.getFeatures().getDatapathId())); list.add(getGranularNodeErrors(message, type, node)); return list; } else { LOG.error("Message is not of Error Message "); return Collections.emptyList(); } }
@Override public Future<RpcResult<Void>> transmitPacket(final TransmitPacketInput input) { LOG.debug("TransmitPacket - {}", input); // Convert TransmitPacket to PacketOutInput final PacketOutConvertorData data = new PacketOutConvertorData(version); data.setDatapathId(sessionContext.getFeatures().getDatapathId()); data.setXid(sessionContext.getNextXid()); final java.util.Optional<PacketOutInput> message = convertorExecutor.convert(input, data); SwitchConnectionDistinguisher cookie = null; ConnectionCookie connectionCookie = input.getConnectionCookie(); if (connectionCookie != null && connectionCookie.getValue() != null) { cookie = new SwitchConnectionCookieOFImpl(connectionCookie.getValue()); } LOG.debug("Calling the transmitPacket RPC method"); return messageService.packetOut(message .orElse(PacketOutConvertor.defaultResult(version)), cookie); }
@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); }
@Override public List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sc, OfHeader msg) { if (msg instanceof MultipartReply && ((MultipartReply) msg).getType() == MultipartType.OFPMPTABLEFEATURES) { LOG.debug("MultipartReply Being translated to TableUpdated "); MultipartReplyMessage mpReply = (MultipartReplyMessage) msg; List<DataObject> listDataObject = new CopyOnWriteArrayList<>(); TableUpdatedBuilder message = new TableUpdatedBuilder(); message.setNode((new NodeRef(InventoryDataServiceUtil.identifierFromDatapathId(sc.getFeatures() .getDatapathId())))); message.setMoreReplies(mpReply.getFlags().isOFPMPFREQMORE()); message.setTransactionId(new TransactionId(BigInteger.valueOf(mpReply.getXid()))); MultipartReplyTableFeaturesCase caseBody = (MultipartReplyTableFeaturesCase) mpReply.getMultipartReplyBody(); MultipartReplyTableFeatures body = caseBody.getMultipartReplyTableFeatures(); final VersionConvertorData data = new VersionConvertorData(sc.getPrimaryConductor().getVersion()); final Optional<List<TableFeatures>> tableFeaturesList = convertorExecutor.convert(body, data); message.setTableFeatures(tableFeaturesList.orElse(Collections.emptyList())); listDataObject.add( message.build()) ; return listDataObject ; } return Collections.emptyList(); }
LOG.warn("Received packet_in, but there is no device datapathId received yet"); } else { BigInteger dpid = features.getDatapathId();
@Override public List<DataObject> translate(SwitchConnectionDistinguisher cookie, SessionContext sc, OfHeader msg) { if(msg instanceof MultipartReply && ((MultipartReply) msg).getType() == MultipartType.OFPMPDESC) { LOG.debug("MultipartReplyMessage - MultipartReplyDesc Being translated to NodeUpdated "); MultipartReplyMessage message = (MultipartReplyMessage) msg; List<DataObject> list = new CopyOnWriteArrayList<DataObject>(); BigInteger datapathId = sc.getFeatures().getDatapathId(); NodeUpdatedBuilder builder = InventoryDataServiceUtil.nodeUpdatedBuilderFromDataPathId(datapathId); FlowCapableNodeUpdatedBuilder fnub = new FlowCapableNodeUpdatedBuilder(); MultipartReplyDescCase caseBody = (MultipartReplyDescCase) message.getMultipartReplyBody(); MultipartReplyDesc body = caseBody.getMultipartReplyDesc(); fnub.setHardware(body.getHwDesc()); fnub.setManufacturer(body.getMfrDesc()); fnub.setSerialNumber(body.getSerialNum()); fnub.setDescription(body.getDpDesc()); fnub.setSoftware(body.getSwDesc()); builder.addAugmentation(FlowCapableNodeUpdated.class, fnub.build()); NodeUpdated nodeUpdated = builder.build(); list.add(nodeUpdated); return list; } else { return Collections.emptyList(); } }
@Override public void onSessionAdded(final SwitchSessionKeyOF sessionKey, final SessionContext context) { GetFeaturesOutput features = context.getFeatures(); BigInteger datapathId = features.getDatapathId(); InstanceIdentifier<Node> identifier = identifierFromDatapathId(datapathId); NodeRef nodeRef = new NodeRef(identifier); NodeId nodeId = nodeIdFromDatapathId(datapathId); ModelDrivenSwitch ofSwitch = new ModelDrivenSwitchImpl(nodeId, identifier, context, convertorExecutor); NotificationQueueWrapper wrappedNotification = new NotificationQueueWrapper( nodeAdded(ofSwitch, features, nodeRef), context.getFeatures().getVersion()); reqOpenflowEntityOwnership(ofSwitch, context, wrappedNotification, rpcProviderRegistry); }
@Override public void onSessionRemoved(final SessionContext context) { GetFeaturesOutput features = context.getFeatures(); BigInteger datapathId = features.getDatapathId(); InstanceIdentifier<Node> identifier = identifierFromDatapathId(datapathId); NodeRef nodeRef = new NodeRef(identifier); NodeId nodeId = nodeIdFromDatapathId(datapathId); unregOpenflowEntityOwnership(nodeId); NodeRemoved nodeRemoved = nodeRemoved(nodeRef); ModelDrivenSwitchRegistration registration = context.getProviderRegistration(); if (null != registration) { registration.close(); context.setProviderRegistration(null); } LOG.debug("ModelDrivenSwitch for {} unregistered from MD-SAL.", datapathId); NotificationQueueWrapper wrappedNotification = new NotificationQueueWrapper( nodeRemoved, context.getFeatures().getVersion()); context.getNotificationEnqueuer().enqueueNotification(wrappedNotification); }
.getMatch(); if (ofMatch != null) { salFlowRemoved.setMatch(fromMatch(ofMatch, sc.getFeatures().getDatapathId(), ofVersion)); } else if (ofFlow.getMatchV10() != null) { final VersionDatapathIdConvertorData data = new VersionDatapathIdConvertorData(sc.getPrimaryConductor().getVersion()); data.setDatapathId(sc.getFeatures().getDatapathId()); .getDatapathId()))); list.add(salFlowRemoved.build()); return list;