2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.openflow.md.core.session;
11 import java.math.BigInteger;
12 import java.security.MessageDigest;
13 import java.security.NoSuchAlgorithmException;
14 import java.util.Arrays;
16 import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher;
21 public class SwitchSessionKeyOFImpl implements SwitchConnectionDistinguisher {
23 protected byte[] encodedId;
24 private BigInteger datapathId;
29 public SwitchSessionKeyOFImpl() {
34 * Special constructor for situation where no datapathId available, do not
35 * call {@link #initId()} on this instance otherwise id will be overwritten.
39 public SwitchSessionKeyOFImpl(byte[] encodedId) {
40 this.encodedId = encodedId;
44 public byte[] getId() {
50 * the datapathId to set
52 public void setDatapathId(BigInteger datapathId) {
53 this.datapathId = datapathId;
57 * compute and set {@link #encodedId} based on {@link #datapathId} and
58 * {@link #auxiliaryId}
60 public void initId() {
62 MessageDigest medi = MessageDigest.getInstance("sha-1");
64 encodedId = medi.digest();
65 } catch (NoSuchAlgorithmException | NullPointerException e) {
66 throw new IllegalArgumentException("can not proceed datapathId: "
72 * extend the content the hash sum is computed from
75 protected void extend(MessageDigest medi) {
76 medi.update(datapathId.toByteArray());
80 public int hashCode() {
83 result = prime * result + Arrays.hashCode(encodedId);
88 public boolean equals(Object obj) {
93 if (getClass() != obj.getClass())
95 SwitchSessionKeyOFImpl other = (SwitchSessionKeyOFImpl) obj;
96 if (!Arrays.equals(encodedId, other.encodedId))